Show Posts
Pages: 1 ... 20 21 [22] 23 24
316  Using Arduino / Programming Questions / Re: LED with Music Notes on: December 28, 2012, 08:13:44 pm
Quote
CC GG AA G
Led1 Led1, Led2 Led2, Led3 Led3, Led2.
[1] The names matching the notes says to me that you want Led1 on while note C is playing, Led2 on when note G is playing, Led3 on when note A is playing.

[2] This is different from turning one led on when the first note plays, two leds on while the second note plays, three on while the third note plays, etc.

Or, maybe I'm not understanding your initial or current desire.

I think y'all are talking past each other a little bit.  I think the code/fix I just posted provides behavior he wants, [1] above.

Cheers,
John
317  Using Arduino / Programming Questions / Re: LED with Music Notes on: December 28, 2012, 08:03:07 pm
...
Also when it plays, it looks like it just lighing the lights in order pin 2-9. I looks ok. but what I was going for was a not assigned to an LED
...

Yes, the "turn on" and "turn off" statements were in the wrong place (and looking at the wrong data).  Notice in the below that I moved them to the playNote() function:

Code:
int speakerPin = 11;

char notes[] = "ccggaagffeeddcggffeedggffeedccggaagffeeddc "; // a space represents a rest
int length = sizeof(notes)/sizeof(notes[0]); // the number of notes
int beats[] = { 1,1,1,1,1,1,2, 1,1,1,1,1,1,2, 1,1,1,1,1,1,2, 1,1,1,1,1,1,2, 1,1,1,1,1,1,2, 1,1,1,1,1,1,2,4,};
int tempo = 1000;  // make this smaller to speed the whole thing up, bigger to slow down
int ledPins[] = { 2,3,4,5, 6,7,8,9};

void playTone(int tone, int duration) {
  for (long i = 0; i < duration * 1000L; i += tone * 2) {
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(tone);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(tone);
  }
}

void playNote(char note, int duration) {
  char names[] = { 'c','d','e','f', 'g','a','b','C'   };
  int tones[] = { 1915,1700,1519,1432, 1275,1136,1014,956   };

  // play the tone corresponding to the note name
  for (int i = 0; i < 8; i++) {
    if (names[i] == note) {
      Serial.println( String(" Note: ") + names[i] + " dur: " + duration + " ledPin: " + ledPins[i]);
      digitalWrite(ledPins[i], HIGH);     // turn on the right LED                 <<********************************
      playTone(tones[i], duration);       // play the note
      digitalWrite(ledPins[i], LOW);      // turn off the LED
    }
  }
}

void setup() {
  pinMode(speakerPin, OUTPUT);
  for (int i=0;i<8; i++)
      pinMode(ledPins[i],OUTPUT);
  Serial.begin(9600);
}


void loop() {
  Serial.println("Start");
  for (int i = 0; i < length; i++) {
    if (notes[i] == ' ') {
      delay(beats[i] * tempo); // rest
    }
    else {
      playNote(notes[i], beats[i] * tempo);
      delay (100);  // make this smaller (or even delete the line) to have less time between the notes, bigger for more
    }
  } 
}
318  Using Arduino / Programming Questions / Re: LED with Music Notes on: December 28, 2012, 08:54:06 am
Ok I fixed the issuse with it starting late..The code was

int ledPins[] = {0,1,2,3,4,5,6,7,8,9};

and Now

int ledPins[] = {2,3,4,5,6,7,8,9};
Great!
Quote
I still get way it stops the lights 8 notes in tho.

If this means "I still don't why it stops after 8 notes though"....

Here is the problem
Code:
    else {
      // here, i is counting from 0 to 41
      digitalWrite(ledPins[i], HIGH);    // but there are only 9 ledPins!
      playNote(notes[i], beats[i] * tempo);
      digitalWrite(ledPins[i], LOW); 
      delay (100);
    }
but
Code:
  for (int i = 0; i < 8; i++) {
    if (names[i] == note) {
      // Here i, represents the note that was found, between 0 and 7 inclusive
      playTone(tones[i], duration);
    }

See if you can figure out how to fix this.  If not I will post the solution tonight...

Cheers,
John
319  Using Arduino / Programming Questions / Re: Sloppy I'm sure, but ALMOST working! on: December 27, 2012, 09:16:11 pm
sure you haven't heard the last of me...  this project is about to get BIG.  I am betting it will soon require more code than the arduino memory can handle... so I bet I will soon be trying to use the cardslot on the ethernet shield to store some of it- with all the headaches that is likely to bring I'm sure I'll be back!

THANKS SO MUCH!

Be sure and let us know the results of your project, and when you get featured in http://hackaday.com/?s=liquor

"Cheers",
John

P.S. the SD card is not going to help you when you're code gets too big...
320  Using Arduino / Programming Questions / Re: LED with Music Notes on: December 27, 2012, 09:07:07 pm
...I am not sure what you mean when you say "Try putting these lines in order"....

Please stare at the following until you understand what "put in order" means smiley

Code:
Σημείωση παίξει (σημειώσεις [i], κτύπησε [i] * ταχύτητα)?  // 2) πείτε το σημείωμα για να παίξει
       ψηφιακής εγγραφής (οδήγησε φως [i], HIGH)?          // 1) για τη σειρά του την κατάλληλη LED
       καθυστέρηση (100)?                                  // 4) 100 χιλιοστά του δευτερολέπτου καθυστέρηση
       ψηφιακής εγγραφής (οδήγησε φως [i], LOW)?           // 3) τη σειρά των LED
321  Using Arduino / Programming Questions / Re: Sloppy I'm sure, but ALMOST working! on: December 27, 2012, 08:08:26 pm
...
 In my code as it stands right NOW, I want it to read the packet, and if it reads "GBLD" I want it to pour my three second glass of vodka.  If it DOESNT read "GBLD" I don't want it to do anything at all.  I thought my code had this down... but apparently not.  The arduino pours the vodka upon seeing ANY packet of information, not matter what it says!  Any ideas? 

Here is the specific area of code:
Quote

void loop()  {
 
 
if (packBuff[0]== 'G' && packBuff[1]=='B' && packBuff[2]=='D' && packBuff[3]=='L'); // If the message sent from my iphone = "GBDL", then run the following script, which should pour vodka for 3 seconds.  NOTE: I am using LEDs as proof of concept right now- later these will be relays.
{
...
}


The problem is the semicolon.  Also, you will find that you are looking for "GBDL", not "GBLD", you'd better double check which you really want...

Cheers,
John
322  Using Arduino / Programming Questions / Re: LED with Music Notes on: December 27, 2012, 07:54:03 pm
John,

Thanks but to tell you the truth its all Greek to me. I am an Network guy. I deal in IP''s address and routing tables. 

I can understand some of it but not all. I am trying to find a good book that examples the Arduino Code and how to use it. But so far I have only seen books that are to Basic or way over my head.

If any one lives the West Palm Beach Fl area and would be willing  to tutor  or over the phone PM me.

Thanks

You're copping out kculm.  Try putting these lines in order:
Code:
      playNote(notes[i], beats[i] * tempo);   // 2) tell the note to play
      digitalWrite(ledPins[i], HIGH);         // 1) turn on the appropriate LED
      delay (100);                            // 4) delay 100 milliseconds
      digitalWrite(ledPins[i], LOW);          // 3) turn of the LED
323  Using Arduino / Programming Questions / Re: LED with Music Notes on: December 27, 2012, 06:37:25 pm
This is what I got, I found it online and just added the rest of the notes.

It works kind of.  It turns on one lite per beat not per not.

I may be to green to take on a task like this.  

Thanks for any help you can give.

Code:
...
    else {
      playNote(notes[i], beats[i] * tempo);
      digitalWrite(ledPins[i], HIGH);
      delay (100);
      digitalWrite(ledPins[i], LOW); 
...

Looks to me like you're pretty close.  But I think what you want to do is:
1) turn on the appropriate LED
2) tell the note to play
3) turn off the LED
4) delay 100 milliseconds

Do you see what you need to change, above?

Cheers,
John
324  Using Arduino / Programming Questions / Re: Array initialising on: December 27, 2012, 01:33:57 pm
Can you tell me the difference between constant, reference and volatile??
Quote
... References are also known as pointers; ...

That's a pretty interesting point of view.

Quote
... there are plenty of internet articles that explain them. ...

Now that part is true, google "c++ reference vs pointer".  This one looks pretty good http://www.embedded.com/electronics-blogs/programming-pointers/4023307/References-vs-Pointers

John
325  Using Arduino / Programming Questions / Re: URGENT!! Aquaponics System w/ monitoring using Time.h and BlinkWithoutDelay on: December 27, 2012, 11:43:35 am
... I pick at your code till I got the alarms working cant have alarms with same name ie has to be pumpalarm1 pumpalarm2 etc.... it in your code I edited and posted it all hope this helps you as much as it has help me been working and testing for 3 hrs enjoy
                                                                                       Thanks dyslexic

1) You don't have to have different function names in the repeatAlarm
2) By default the library allows a max of 6 repeating Alarms, see the readme.txt file in .../libraries/TimeAlarms

Good luck,
John
326  Using Arduino / Programming Questions / Re: Blink Without Delay Help on: December 26, 2012, 12:13:22 pm
i got this code
Code:
...
void loop()
{
  for (int i = 0; i<50;i++)
 {
  switch (state){
  case 1:
    digitalWrite(Led,HIGH);
    currentMillis = millis();
    state=2;
it compile but cant do anything at all

Hi Ash,

You don't need a for loop because the whole loop() function gets called over and over already by the Arduino framework.  You only need to keep track of when things need to happen, and if it's time for something to happen.  See if you can understand this version.  Good luck!

Code:
const int LED=11;
void setup(){
    pinMode(LED, OUTPUT);
}

long nextTime=0;
bool nextState=HIGH;
long count;

void loop(){
    long currentTime=millis();
    if (currentTime < nextTime) return;  // if not time for something to happen, just return

    // it's now time to make nextState happen
    if (nextState==HIGH){
        // turn it on and schedule OFF in 5 seconds
        digitalWrite(LED, HIGH);
        nextState=LOW;
        nextTime = currentTime + 5000;
    }
    else {
        // turn it off and schedule ON in the right number of seconds according to "count"
        digitalWrite(LED, LOW);
        nextState=HIGH;
        if (count < 11){ nextTime=currentTime + 5000; }
        else if (count < 21){ nextTime=currentTime + 4000; }
        else if (count < 31){ nextTime=currentTime + 3000; }
        else if (count < 41){ nextTime=currentTime + 2000; }
        else if (count < 51){ nextTime=currentTime + 1000; }
        else {
            // what should happen after it has blinked 50 times?
        }
        count = count + 1;    // or just "count++'"
    }
}

327  Using Arduino / Programming Questions / Re: Blink Without Delay Help on: December 26, 2012, 10:33:26 am
That article is confused. Once you work in unsigned's, you forget about negative.
...

Which article?
328  Using Arduino / Programming Questions / Re: Audioino? on: December 24, 2012, 02:47:14 pm
I understand how isp works. Can I not use Arduino as ISP for something like this? I have ordered a usbasp but even when I get it, dont I have to edit the boards.txt file for the bootloader to show up on the arduino IDE so i can burn the bootloader? Thats the part I am confused on.

This seems to be a pretty good link about burning bootloaders using Arduino as ISP: http://www.ladyada.net/library/arduino/arduinoisp.html.  See the very last bit about using the avrdude command line to be able to specify a different bootloader's hex file.

Let us know how you come with this, it sounds pretty interesting to me!  I wonder if you could install a wav file to such a device using an iPhone or Android...

John
329  Using Arduino / Programming Questions / Re: Meeting a variable created in setup(). on: December 20, 2012, 04:40:21 pm
Very nice, I didn't know the malloc() funtion. The only doubt is that I am only used to managing double array by rows and columns. With this code how I know how many rows and columns there are?
Does this help:
Code:
byte **variable = NULL;
int rows;
int cols;
void setup()
{
  rows = EEPROM.read(0);
  cols =  EEPROM.read(1);
  // Here I already know the sizes.
   variable = (byte **)malloc(rows * cols * sizeof(byte));
}

void loop()
{
  // "Handling variable" as you put it
   for (int r=0; r<rows; r++)
     for (int c=0; c<cols; c++) {
        variable[r][c] = 17;
     }
}

330  Development / Suggestions for the Arduino Project / Re: String corrupts the heap and crashes on: December 20, 2012, 12:24:22 pm
Ok, thanks.

I remember last year when starting with Arduinos, finding that problem and eventually your malloc.c fix in the bug report.

A few months ago I discovered Teensy and have mostly been using them since...

Cheers,
John
Pages: 1 ... 20 21 [22] 23 24