Go Down

Topic: LED with Music Notes (Read 3017 times) previous topic - next topic

PaulS

Quote
Try putting these lines in order:

Is step 4 really necessary? That will REALLY slow the song down.

kculm

John,

I am not copping out, I am just not getting it.

I sure you have better things to do, but you get some free time do you think you can set it up on a breadboard and see what I see.  Like I said I am sure you have better things to do.

I am not sure what you mean when you say "Try putting these lines in order".

I am very thankful for your time and help.


PaulS

Quote
I am not sure what you mean when you say "Try putting these lines in order".

Did you look at the comments on those 4 lines John posted?

johncc


...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 :)

Code: [Select]

???????? ?????? (?????????? [i], ??????? [i] * ????????)?  // 2) ????? ?? ???????? ??? ?? ??????
       ???????? ???????? (??????? ??? [i], HIGH)?          // 1) ??? ?? ????? ??? ??? ????????? LED
       ??????????? (100)?                                  // 4) 100 ???????? ??? ????????????? ???????????
       ???????? ???????? (??????? ??? [i], LOW)?           // 3) ?? ????? ??? LED

kculm

Ok Is this what you mean. I hope. If not I am going to feel like a real Dumb A%#.


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

kculm

It working a little better. 

The Lights to don't come until 3 notes in and they stop after about 8. 

I am going to go over the code to see what i can see

Thanks for all the help.

kculm

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};

Like I stated earlyer in the Post. it will using and EL Escudo Dos  to run EL wire

EL Escudo Dos  use pins 2- 9 and 13. 

I still get way it stops the lights 8 notes in tho.

robtillaart


You must read the code and be the processor and follow it step by step what it does. Use pencil and paper to write down the state of variables.

Although it may sounds stupid at first you will see through the eyes of the processor and learn a lot ;)


Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

johncc


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: [Select]

    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: [Select]

  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

kculm




Quote

I still get way it stops the lights 8 notes in tho.

Quote

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


It was late, lol but yes that is what I was trying to say.

kculm



You must read the code and be the processor and follow it step by step what it does. Use pencil and paper to write down the state of variables.

Although it may sounds stupid at first you will see through the eyes of the processor and learn a lot ;)





The issue is I am still learning the code. so its not all making sense to me yet.
but ill keep plugin along.

kculm

John I am sorry but I can't figure it out.  I will need your help.

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


ie C Led1 G Led2 A Led3 and so on. this way when that noted played more then once the Led would light.

thanks





Here is the problem
Code: [Select]

    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: [Select]

  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

PaulS

Quote
this way when that noted played more then once the Led would light.

So, you simply want to turn another LED on each time another note is played? That is not what you first asked for.

kculm

I am very thank for the help I am getting and I am learning a lot.  Not to sound ungrateful but I did mention that in the begin of this post. Don't get me wrong I can live with it the way it is until I learn more. I know I have a long way to go.


Hey gang

twinkle twinkle uses 6 notes, A C D E F G. I would like to blink an LED to correspond to a Note.

i.e. C Led1 , G Led2, A Led3

It would look something like this

CC GG AA G
Led1 Led1, Led2 Led2, Led3 Led3, Led2.

It would be great to someone had some code to look at or point me in the right direction

johncc


...
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: [Select]
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
    }
  } 
}

Go Up