Show Posts
Pages: [1] 2
1  Using Arduino / General Electronics / Re: Using Oscillator as a Crystal on: March 02, 2012, 04:38:58 pm
By "default AVR mode" do you mean the default fuse settings? Good question...officially, you're supposed to change the fuses depending on the clock source, but I'm wondering if it just might work to leave the fuses the way they are. I think it's worth an experiment. The worst that could happen is you damage the clock circuitry on the Arduino and a) it fails to work at all, or b) it will never work again using a crystal. Either way, with a DIP microcontroller that can be swapped out it's a pretty inexpensive experiment.

Personally, I'd buy a $30 AVR-ISP and have something that is known to work smiley  I use my AVR-ISP so often that the $30 has paid for itself many times over.

--
The Flexible MIDI Shield: MIDI IN/OUT, stacking headers, your choice of I/O pins


Is this something I could also use to upload sketches and burn the bootloader?
2  Using Arduino / General Electronics / Re: Using Oscillator as a Crystal on: March 02, 2012, 04:01:01 pm
Hmm, thanks. But does that mean there's no way to do it in the Arduino's default AVR mode?
3  Using Arduino / General Electronics / Using Oscillator as a Crystal on: March 02, 2012, 03:29:43 pm
I'm trying to get my ATMega328 off the Arduino board and onto a breadboard. I know I need a quartz crystal (the small oval with 2 leads) between two of the pins. However, all I have is an oscillator (a large rectangle with 4 leads). Is it possible to use the oscillator as a crystal?
4  Using Arduino / Programming Questions / Re: Variables in switch statements on: December 03, 2011, 02:15:26 pm
Thanks for the quick replies guys.

Hmm, I've never had a problem with not being able to store the codes in an int, unless of course the wraparound would be the same.
Anyway, I've solved the problem by making the variables that store the codes for each button constants.

Code:
const int power = XXXXXXXXXXX;

AWOL, what's a lookup and how do I use it?
5  Using Arduino / Programming Questions / Variables in switch statements on: December 03, 2011, 01:43:52 pm
Hey. Is it possible to use a variable in a switch statement? I'm doing a project based on TV remote IR codes and using variables to concisely store the long codes. Also, using the codes themselves in switch statements would be impractical, since if I started using a different remote, I would only have to change the codes in one place at the top. So, is it possible?

Code:
//import IRremote Library
#include <IRremote.h>

//define remote button data codes
int power = 31377463;
int play = 31352983;
int stp = 31385623;
int rewind = 31365223;
int forward = 31332583;
int menu = 31329013;
int enter = 31367773;
int no1 = 31359103;
int no2 = 31342783;
int no3 = 31375423;
int no4 = 31334623;
int no5 = 31367263;

//LED status variables (0 = off; 1 = on)
int a,b,c,d,e,x = 0;

//pin definitions
int ledPin1 = 12;
int ledPin2 = 11;
int ledPin3 = 10;
int ledPin4 = 9;
int ledPin5 = 8;
int RECV_PIN = 2;

//variable for storing recieved data code
int CODE;

IRrecv irrecv(RECV_PIN);
decode_results results;

void setup() {

  Serial.begin(9600);       //enable serial console for debugging
  irrecv.enableIRIn();      //enable IR recieving
  pinMode(ledPin1, OUTPUT); //LED pin output enabling
  pinMode(ledPin2, OUTPUT);
  pinMode(ledPin3, OUTPUT);
  pinMode(ledPin4, OUTPUT);
  pinMode(ledPin5, OUTPUT);

}

void loop() {

  if (irrecv.decode(&results)) {

    Serial.println(results.value);
    CODE = (results.value);

    switch (CODE) {

    case no1:
      if (a == 0) {
        digitalWrite(ledPin1, HIGH);
        a = 1;
      }

      else {
        digitalWrite(ledPin1, LOW);
        a = 0;
      }

      break;

    case no2:
      if (b == 0) {
        digitalWrite(ledPin2, HIGH);
        b = 1;
      }

      else {
        digitalWrite(ledPin2, LOW);
        b = 0;
      }

      break;

    case no3:
      if (c == 0) {
        digitalWrite(ledPin3, HIGH);
        c = 1;
      }

      else {
        digitalWrite(ledPin3, LOW);
        c = 0;
      }

      break;

    case no4:
      if (d == 0){
        digitalWrite(ledPin4, HIGH);
        d = 1;
      }

      else {
        digitalWrite(ledPin4, LOW);
        d = 0;
      }

      break;

    case no5:
      if (e == 0){
        digitalWrite(ledPin5, HIGH);
        e = 1;
      }

      else {
        digitalWrite(ledPin5, LOW);
        e = 0;
      }

      break;

    case power:
      if (x == 0) {
        digitalWrite(ledPin1, HIGH);
        digitalWrite(ledPin2, HIGH);
        digitalWrite(ledPin3, HIGH);
        digitalWrite(ledPin4, HIGH);
        digitalWrite(ledPin5, HIGH);
        x = 1;
        a = 1;
        b = 1;
        c = 1;
        d = 1;
        e = 1;
      }

      else {
        digitalWrite(ledPin1, LOW);
        digitalWrite(ledPin2, LOW);
        digitalWrite(ledPin3, LOW);
        digitalWrite(ledPin4, LOW);
        digitalWrite(ledPin5, LOW);
        x = 0;
        a = 0;
        b = 0;
        c = 0;
        d = 0;
        e = 0;
      }

      if (a == 1 && b == 1 && c == 1 && d == 1 && e == 1) {
       
        x = 1;
       
      }
     
      if (a,b,c,d,e == 0) {
       
        x = 1;
       
      }
     
      Serial.println(x);
      delay(500);
      irrecv.resume();
     
    }

  }

}

^^^That gives me "'no1' cannot appear in a constant expression."
6  Forum 2005-2010 (read only) / Syntax & Programs / Re: Arduino Capabilities - Lengthy equations? on: January 03, 2011, 07:11:33 pm
By the way, mind telling us what you're working on?  ;D
7  Forum 2005-2010 (read only) / Syntax & Programs / Re: Arduino Capabilities - Lengthy equations? on: January 03, 2011, 06:37:40 pm
Hey there. As far as I know, it should be fine. What you will have to make sure of though, is to use the right data type. For example, an unsigned int takes relatively little memory to store, but it also only has a range of 0 to about 32000. A float, on the other hand is between 3.4028235E+38 and -3.4028235E+38 and has 6-7 digits of resolution, including decimals but uses significantly more room.

What you also might encounter is a pause or slowdown in your code due to the intensive math you have to do. So if you are sampling data only, say, once every 30 min, you should be fine.

In conclusion, a dog can dig, but a backhoe is much faster. The Arduino will do it, but thats not to say it wont break a sweat.

8  Forum 2005-2010 (read only) / Syntax & Programs / Re: Debouncing IR on: December 22, 2010, 08:57:37 am
Thanks guys. Ironically Lefty, the key that I want to be able to press twice in a row is the one that's giving me trouble. How would using millis() to wait x seconds after a code is received to receve the next code look like I was thinking

Code:
when code received
x = millis

after doing something

y = millis()

if y-x >= 500

receive next code


9  Forum 2005-2010 (read only) / Syntax & Programs / Debouncing IR on: December 21, 2010, 08:00:38 pm
So i have a nice little IR remote setup; its pretty useless but fun. I do have a slight problem though. My remote seems to like to send many copies of the same code(like pressing the button many times) so you end up having to barely push the button for it to register only one button press. Is there a way to debounce it or decrease the IR sampling freqency without using delay()?

10  Forum 2005-2010 (read only) / Syntax & Programs / Re: Changing funcation depending on state? on: December 20, 2010, 08:27:45 pm
Thanks for the reply. I made the turning on of the led change the value of a variable. The led can only turn on if the variable is a certain value.

Code:
 if (CODE == power){
      if (x == 0){
        digitalWrite(ledPin1, HIGH);
        digitalWrite(ledPin2, HIGH);
        digitalWrite(ledPin3, HIGH);
        x = 1;
      }


        else{
          digitalWrite(ledPin1, LOW);
          digitalWrite(ledPin2, LOW);
          digitalWrite(ledPin3, LOW);
          x = 0;
        }
      }
I ended up using this to control 3 leds. The only thing is that if you use this to turn the leds on, then turn them off manually, you have to push power twice for the variable to be readjusted. Any suggestions?
11  Forum 2005-2010 (read only) / Syntax & Programs / Changing funcation depending on state? on: December 20, 2010, 06:15:42 pm
Hi everybody. What I'm trying to do is to make a "button" (I'm using IR so effectively it would be "if a certain code is received") that will turn an led on if it is off and turn it off if it is on. In other words, to turn your TV on and off, you use the same button, but the button changes functions depending on whether the TV is on or off. Here's what I have so far(its not working, BTW):

Code:
if (CODE == POWER){
    if (ledPin3 == LOW){
      digitalWrite(ledPin3, HIGH);
    }
    if (ledPin3 == HIGH){
      digitalWrite(ledPin3, LOW);
    }
12  Forum 2005-2010 (read only) / Syntax & Programs / Re: Melody Player Visualizer on: December 14, 2010, 09:21:12 am
Yeah, I began to suspect that the Arduino started the tone and let it finish while it went on to the next line. Thanks for the reply though. It's such an elegant solution. I'll try it out went I have access to my Arduino.
13  Forum 2005-2010 (read only) / Syntax & Programs / Melody Player Visualizer on: December 13, 2010, 08:11:19 pm
So I cleaned up and modified the melody example sketch to play my own melody. Its going fine and sounds pretty damn cool. I've tried to add a "visualizer" led for each note that stays on for the entire note and is off in the time between the note. The furthest I could get was having the led blink once at the beggining of the note. Any tips?

Note: I've very easily done it by simply hooking the led up in series with the peizo, but i want to do it using a seperatae pin (i.e. on the software side of things.

heres the code

Code:
/*A simple program that plays Zelda'a Lulluby using a peizo speaker. Also has adjustable volume and speed using potentiometers. Pitch modification is also in the works.
HOOKUP: Pot 1 lead A hooked up to digital pin 8. Sweeper to positive of peizo. Lead B to ground. Peizo negative to ground. Pot 2 lead A hooked up to 5V. Sweeper to analog 0. Lead B to ground.   */




#include "pitches.h";                                                 //Include the file pitches.h which assigns specific frequencies to notes the peizo should play

int melody[] = {                                                      //Define the melody as being the notes following using those defined in pitches.h
NOTE_E4, NOTE_G4, NOTE_D4, NOTE_C4, NOTE_D4,
NOTE_E4, NOTE_G4, NOTE_D4,   0,     NOTE_E4,
NOTE_G4, NOTE_D5, NOTE_C5, NOTE_G4, NOTE_F4,
NOTE_E4, NOTE_D4,    0,    NOTE_E4, NOTE_G4,
NOTE_D4, NOTE_C4, NOTE_D4, NOTE_E4, NOTE_G4,
NOTE_D4,    0,    NOTE_E4, NOTE_G4, NOTE_D5,
NOTE_C5, NOTE_G4};

int noteDurations[] = {                                               //Define the note durations, 1 to 1 with melody    1 = 8 beats
  2,4,2,8,8,                                                          //                                                 2 = 4 beats (whole note)
  2,4,2,4,2,                                                          //                                                 4 = 2 beats (half note)
  4,2,4,2,8,                                                          //                                                 8 = 1 beats (quarter note)
  8,2,4,2,4,
  2,8,8,2,4,
  2,4,2,4,2,
  4,1 };
  
int sensorPin = 0;                                                    //Define the analog (pot.) input pin
int sensorValue = 2000;                                               //Establish the default sensor value
int ledPin = 13;                                                      //Define the pin the led is on

void setup()
 {
  pinMode(ledPin,OUTPUT);                                             //make the led pin an output
 }

void loop() {
   for (int thisNote = 0; thisNote < 32; thisNote++)                  //Make the note to be played #0. For each note value below "32," do the below and increase the note number by 1
   {              
    sensorValue = analogRead(sensorPin);                              //Read the sensor pin in analog (actual value vs 1 or 0) and make the sensor value equal to that reading
    int noteDuration = sensorValue*3/noteDurations[thisNote];         //Make the duration of each note (in milliseconds) twice the sensor value divided by the note durations previously established
    digitalWrite(ledPin, HIGH);                                       //Make the digital pin that the led is on HIGH, or 5V (basically: turn the led on)
    tone(8, melody[thisNote],noteDuration);                           //Play a tone with certain pararmeters: from melody, use note #X (accoring to the first line) with the previously calculated note duration
    digitalWrite(ledPin, LOW);                                        //Make the digital pin that the led is on LOW, or 0V (basically: turn the led off)
    int pauseBetweenNotes = noteDuration * 1.30;                      //Make the pause between notes 1.3 times the duration of the previous note
    delay(pauseBetweenNotes);                                         //Wait the previously calculated pause between notes before starting the next cycle and playing the next note
   }
}




the analog is for modifying speed, no issues with that
14  Forum 2005-2010 (read only) / Interfacing / Re: Dim LED Matrix on: January 15, 2011, 08:15:53 pm
Thanks for the reply but Im not sure what you mean by first instance
15  Forum 2005-2010 (read only) / Interfacing / Dim LED Matrix on: January 15, 2011, 05:45:13 pm
Hi. Im using a 8x8 matrix with the Arduino RowColumnScanning example sketch (with slight modification). Its working "fine," but the LED's are MUCH dimmer than they are when they are manually set. Anybody know what's causing this?

Code:
const int col[8] = {
  [glow]2,3,4,5,6,7,8,9[/glow] };

const int row[8] = {
  [glow]10,11,12,13,16,17,18,19[/glow]  };

int pixels[8][8];          

int x = 5;
int y = 5;

void setup() {
  for (int thisPin = 0; thisPin < 8; thisPin++) {

    pinMode(col[thisPin], OUTPUT);
    pinMode(row[thisPin], OUTPUT);  

    digitalWrite(col[thisPin], HIGH);    
  }

  for (int x = 0; x < 8; x++) {
    for (int y = 0; y < 8; y++) {
      pixels[x][y] = HIGH;
    }
  }
}

void loop() {
  readSensors();

  refreshScreen();
}

void readSensors() {

  pixels[x][y] = HIGH;

  x = map(analogRead(A0), 0, 1023, 0, 7);
  y =7- map(analogRead(A1), 0, 1023, 0, 7);

  pixels[x][y] = LOW;

}

void refreshScreen() {

  for (int thisRow = 0; thisRow < 8; thisRow++) {

    digitalWrite(row[thisRow], HIGH);

    for (int thisCol = 0; thisCol < 8; thisCol++) {

      int thisPixel = pixels[thisRow][thisCol];

      digitalWrite(col[thisCol], thisPixel);

      if (thisPixel == LOW) {
        digitalWrite(col[thisCol], HIGH);
      }
    }

    digitalWrite(row[thisRow], LOW);
  }
}
Pages: [1] 2