Pages: 1 [2] 3   Go Down
Author Topic: LED with Music Notes  (Read 1890 times)
0 Members and 1 Guest are viewing this topic.
Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46042
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Try putting these lines in order:
Is step 4 really necessary? That will REALLY slow the song down.
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.

Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46042
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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?
Logged

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

...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
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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


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

Offline Offline
Full Member
***
Karma: 1
Posts: 209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 168
Posts: 12430
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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 smiley-wink


Logged

Rob Tillaart

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

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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.
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


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 smiley-wink




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

Offline Offline
Full Member
***
Karma: 1
Posts: 209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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:
    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
Logged

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 548
Posts: 46042
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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.
Logged

Offline Offline
Full Member
***
Karma: 1
Posts: 209
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

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
Logged

Temple, Texas
Offline Offline
Sr. Member
****
Karma: 14
Posts: 354
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

...
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
    }
  } 
}
Logged

Pages: 1 [2] 3   Go Up
Jump to: