sorry for the messy code. I was in hurry so I just upload everything without delete the unwanted parts
here is my code
const int led[] = {1, 2, 3, 4, 5};
const int buttonPin = 7;
int potValue = 0;
int potPIN = 0;
int n = random(1, 10);
int buttonState = 0;
int speakerPin = 13;
int rightLight = 1;
int rightLight2 = 3;
int length = 2; // the number of notes
char notes[] = "ccggaagffeeddc "; // a space represents a rest
int beats[] = { 1, 1, 1, 1, 1, 1, 2, 1, 1, 1, 1, 1, 1, 2, 4 };
int tempo = 100;
int win;
int j;
int k;
void randLight () //loops the lights
{
for(int i = 0; i<=5; i++)
{
j = random(0,5);
k = random(0,5);
if(j== rightLight || k== rightLight2) //This is the light that you are trying to target
{
//win = 1; //when this is one, and you press the button, you win
potValue = analogRead(potPIN);
potValue = (potValue/3 + 10);
digitalWrite(led[j,k], HIGH);
delay(potValue);
digitalWrite(led[j,k], LOW);
delay(potValue);
digitalWrite(led[j,k], HIGH);
delay(potValue);
digitalWrite(led[j,k], LOW);
//win = 0; //when this is zero, and you press the button, you lose
//delay(potValuen);
if(led[j,k] == HIGH)
{
win == 1;
}
}
else { //all other lights than the target light
digitalWrite(led[j,k], HIGH);
delay(3potValue);
digitalWrite(led[j,k], LOW);
delay(potValue*n);
}
}
}
void playTone(int tone, int duration)
{
win = led[j,k];
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH && win == 1)
{
for (long i = 0; i < duration * 1000L; i += tone * 2)
{
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tone);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tone);
}
} else
{
//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 == note)
- {*
_ playTone(tones*, duration);_
_ }_
_ }_
_}_
void setup()
_{_
_ pinMode(buttonPin, INPUT);//set push button as input*_
* for (int i = 0; i < 5; i++)//condition loop*
* {*
_ pinMode (led*, OUTPUT);//set led light as output*
* }
pinMode(speakerPin, OUTPUT);//set speaker at output*
}
void loop()
{
* randLight();*_
* for (int i = 0; i < length; i++)*
* {*
_ if ( notes == ' ')
* {_
delay(beats _ tempo); // rest_
* } else {*
playNote(notes, beats * tempo);
* }*
* //pause between notes*
* delay(tempo / 2);*
* }*
}