I'm a total noob with the arduino and have never even attempted anything close to programming - the learning is slow-going. I have tried to look into making 8 LEDs blink one at a time in synchronization with a simple piezo buzzer. I'm not exactly sure how to write the code so it will work. I know that I have to use the if/else rule?? but i'm not sure how to execute that. Please forgive my lack of knowledge and terminology, but I trust you're all quite capable. The code I'm working with is under the cut w/ a pic of my breadboard set-up
Thanks in advance! -monti
int speakerPin = 5;
int ledPins[] = {13,12,11,10,9,8,7,6};
int length = 13;
char notes[] = "cdefgabCbafed";
int beats[] = { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 };
int tempo = 50;
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 };
for (int i = 0; i < 8; i++) {
if (names == note) {
_ playTone(tones*, duration);_
_ }_
_}_
_}_
void setup() {
pinMode(speakerPin, OUTPUT);
*for(int i = 0; i < 8; i++){ *
_ pinMode(ledPins,OUTPUT);
}
}
void loop() {
for (int i = 0; i < length; i++) {
if (notes == ' ') {_
delay(beats _ tempo); // rest_
* } else {*
playNote(notes, beats * tempo);
* }*
* // pause between notes*
* delay(tempo / 2);*
}
int delayTime = 50;
for(int i = 0; i <= 7; i++){
* int offLED = i - 1;*
* if(i == 0) {*
* offLED = 7;*
* }*
_ digitalWrite(ledPins*, HIGH);
digitalWrite(ledPins[offLED], LOW);
delay(delayTime);
}
}_
*