Seattle, WA USA
Offline
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #15 on: December 27, 2012, 08:40:15 pm » |
Try putting these lines in order: Is step 4 really necessary? That will REALLY slow the song down.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 175
|
 |
« Reply #16 on: December 27, 2012, 08:46:40 pm » |
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
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #17 on: December 27, 2012, 08:48:54 pm » |
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
Sr. Member
Karma: 14
Posts: 354
|
 |
« Reply #18 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  Σημείωση παίξει (σημειώσεις [i], κτύπησε [i] * ταχύτητα)? // 2) πείτε το σημείωμα για να παίξει ψηφιακής εγγραφής (οδήγησε φως [i], HIGH)? // 1) για τη σειρά του την κατάλληλη LED καθυστέρηση (100)? // 4) 100 χιλιοστά του δευτερολέπτου καθυστέρηση ψηφιακής εγγραφής (οδήγησε φως [i], LOW)? // 3) τη σειρά των LED
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 175
|
 |
« Reply #19 on: December 28, 2012, 12:50:13 am » |
Ok Is this what you mean. I hope. If not I am going to feel like a real Dumb A%#. digitalWrite(ledPins[i], HIGH); playNote(notes[i], beats[i] * tempo); digitalWrite(ledPins[i], LOW); delay (100);
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 175
|
 |
« Reply #20 on: December 28, 2012, 12:58:35 am » |
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
Full Member
Karma: 1
Posts: 175
|
 |
« Reply #21 on: December 28, 2012, 01:22:56 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};
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
|
|
|
|
|
Netherlands
Online
Tesla Member
Karma: 87
Posts: 9383
In theory there is no difference between theory and practice, however in practice there are many...
|
 |
« Reply #22 on: December 28, 2012, 03:26:32 am » |
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 
|
|
|
|
|
Logged
|
|
|
|
|
Temple, Texas
Offline
Sr. Member
Karma: 14
Posts: 354
|
 |
« Reply #23 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! 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 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 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
Full Member
Karma: 1
Posts: 175
|
 |
« Reply #24 on: December 28, 2012, 09:35:51 am » |
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"....
It was late, lol but yes that is what I was trying to say.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 175
|
 |
« Reply #25 on: December 28, 2012, 09:40:50 am » |
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.
|
|
|
|
|
Logged
|
|
|
|
|
Offline
Full Member
Karma: 1
Posts: 175
|
 |
« Reply #26 on: December 28, 2012, 07:25:38 pm » |
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 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 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
Brattain Member
Karma: 311
Posts: 35470
Seattle, WA USA
|
 |
« Reply #27 on: December 28, 2012, 07:56:51 pm » |
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
Full Member
Karma: 1
Posts: 175
|
 |
« Reply #28 on: December 28, 2012, 08:02:01 pm » |
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
Sr. Member
Karma: 14
Posts: 354
|
 |
« Reply #29 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: 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
|
|
|
|
|
|