Thanks for the help but just needed to take a break from it and come back.
Ok I’m new to Arduino and programming in general, but i am capable and really interested in electronics and really want to learn.
So I’m staring off trying to make a little thing that plays this->http://arduino.cc/en/Tutorial/Tone melody and have a separate LED blink for each note after a button is pushed.
I understand all the wiring and had it set up to play the melody on the button push but im having trouble getting the LEDS to sync with the notes, could someone please help me with this:
#include "pitches.h"
int button = 2;
int led1 = 13;
int led2 = 12;
int led3 = 11;
int led4 = 10;
int speaker = 8;
int melody[] = {
NOTE_C4, NOTE_G3,NOTE_G3, NOTE_A3, NOTE_G3,0, NOTE_B3, NOTE_C4};
int noteDurations[] = {
4, 8, 8, 4,4,4,4,4 };
int ledsequence[] = {
led1, led2, led2, led3, led2, led4, led1};
void setup() {
Serial.begin(9600);
pinMode(button, INPUT_PULLUP);
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
pinMode(led4, OUTPUT);
pinMode(speaker, OUTPUT);
}
void loop()
{
int state = digitalRead(button);
Serial.println(state);
delay(5);
if (state == 0)
{
for (int thisNote = 0; thisNote < 8; thisNote++) {
int noteDuration = 1000/noteDurations[thisNote];
int pauseBetweenNotes = noteDuration * 1.30;
digitalWrite(ledsequence[thisNote],HIGH);
delay(noteDuration);
digitalWrite(ledsequence[thisNote],LOW);
delay(pauseBetweenNotes);
tone(8, melody[thisNote],noteDuration);
delay(pauseBetweenNotes);
}
}
}