Hey guys,
I just finished all the included Arduino circuits, and today I built my own custom circuit board. The idea is that if you press one button on the circuit board, a piezo element will play a small song, then the other button will play another song. All the while the LEDs will be blinking. I just wrote up some code and I am getting error messages that I am not sure how to fix. I would also appreciate any tips you can give me. Thanks a Lot.
HERE ARE THE ERROR MESSAGES:
sketch_feb08a:8: error: initializer fails to determine size of 'ledPins'
sketch_feb08a.ino: In function 'int frequency(char)':
sketch_feb08a:24: error: initializer fails to determine size of 'names'
sketch_feb08a:25: error: initializer fails to determine size of 'frequencies'
sketch_feb08a:26: error: 'numNotes' was not declared in this scope
sketch_feb08a.ino: In function 'void setup()':
sketch_feb08a:46: error: expected `;' before ')' token
sketch_feb08a.ino: In function 'void loop()':
sketch_feb08a:66: error: 'songLenth1' was not declared in this scope
sketch_feb08a:88: error: 'songLenth2' was not declared in this scope
HERE IS THE CODE:
//Code Project 1: Piezo Element and Push Button LEDs
//Beginning Variables
const int button1Pin = 12; // pushbutton 1 pin
const int button2Pin = 13; // pushbutton 2 pin
const int buzzerPin = 9; //Piezo Element
int ledPins[] = (5,6,10,11);
int songLength1 = 31; //Twinkle Twinkle Little Star
char notes1[] = "ccggaagffeeddcggffeedggffeedccggaagffeeddc ";
int beats1[] = {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,1};
int tempo1 = 100;
int songLength2 = 28; //Do You Know the Muffin Man
char notes2[] = "gccdecccaddcbgggccdecccddggc ";
int beats2[] = {1,1,1.5,.75,1,1,1.5,.75,1,1,1.5,.75,1,1,1.5,1,1,1,.75,1,1,1.5,1,1,1,1,1,2,1};
int tempo2 = 100;
int frequency(char note) //Piezo Element Notes
{
int i;
const int numnotes = 8;
char names[] = ( 'c', 'd', 'e', 'f', 'g', 'a', 'b', 'c' );
int frequencies[] = (262, 294, 330, 349, 392, 440, 494, 523);
for (i=0; i < numNotes; i++)
{
if (names == note)
- {*
_ return(frequencies*);_
_ }_
_ }_
_ return(0);_
_}_
_//Ending Variables*_
//Beginning Setup
void setup()
{
* pinMode(buzzerPin, OUTPUT);*
* pinMode(button1Pin, INPUT);*
* pinMode(button2Pin, INPUT);*
* int index;*
* for(index = 0); index <= 7; index++)*
* {*
* pinMode(ledPins[index], OUTPUT);*
* }*
}
//Ending Setup
//Beginning Loop
void loop()
{
* int button1State, button2State; //Push Button*
* button1State = digitalRead(button1Pin); //Push Button*
* button2State = digitalRead(button2Pin); //Push Button*
* if (button1State == HIGH) //If Button1 is pushed, Play "Twinkle Twinkle Little Star"*
* {*
* int i, duration; //Piezo Element*
* for (i = 0; i < songLenth1; i++)*
* {*
duration = beats1 * tempo1;
_ if (notes1 == ' ')
* {
delay(duration);
}
else*
* {
tone(buzzerPin, frequency(notes1), duration);
delay(duration);
}
delay(tempo1/10);
}
}*_
* if (button2State == HIGH) //If Button2 is pushed, Play "Do You Know the Muffin Man"*
* {*
* int i, duration; //Piezo Element*
* for (i = 0; i < songLenth2; i++)*
* {*
duration = beats2 * tempo2;
_ if (notes2 == ' ')
* {
delay(duration);
}
else*
* {
tone(buzzerPin, frequency(notes2), duration);
delay(duration);
}
delay(tempo2/10);
}
}
oneAfterAnotherLoop(); //LED Light Sequence*_
}
//Ending Loop
//Begin LED Light Sequence
void oneAfterAnotherLoop()
{
int index;
int delayTime = 100;
for(index = 0; index <= 7; index++)
* {*
* digitalWrite(ledPins[index], HIGH);*
* delay(delayTime);*
* }*
for(index = 7; index >= 0; index--)
* {*
* digitalWrite(ledPins[index], LOW);*
* delay(delayTime);*
* }*
}
//End LED Light Sequence
//End Code