Hey there, I'm making a basic Arduino game for a school project, the idea is to have 3 lights, 2 red and 1 green. It constantly cycles through the three with the green in the middle, the user needs to click the button while the light is green to win, if the light is red he loses, it's kind of like a rythm / reaction game. I've been trying to program it but nothing seems to work. I am a fairly new user so I don't quite know everything there is to know, can anyone see an obvious error my my code that would cause it not to work?
Code:
#include "pitches.h"
int led1 = 13;
int led2 = 12;
int led3 = 11;
const int threshold = 10;
int i = 1;
int notes[] = {
NOTE_A4, NOTE_B4,NOTE_C4,NOTE_AS4,NOTE_D4 };
void setup() {
pinMode(led1, OUTPUT);
pinMode(led2, OUTPUT);
pinMode(led3, OUTPUT);
}
void loop() {
for(i=0; i<3; i++) {
if (i=0) {
digitalWrite(led1, HIGH);
delay(200);
digitalWrite(led2, LOW);
delay(0);
digitalWrite(led3, LOW);
delay(0);
int sensorReading = analogRead(0);
if (sensorReading > threshold) {
tone(8, NOTE_C4, 20);
tone(8, NOTE_D4, 20);
}
}
if (i=1) {
digitalWrite(led2, HIGH);
delay(200);
digitalWrite(led1, LOW);
delay(0);
digitalWrite(led3, LOW);
delay(0);
int sensorReading = analogRead(0);
if (sensorReading > threshold) {
tone(8, NOTE_A4, 20);
tone(8, NOTE_AS4, 20);
tone(8, NOTE_B4, 20);
tone(8, NOTE_C4, 20);
}
}
if (i=2) {
digitalWrite(led3, HIGH);
delay(200);
digitalWrite(led1, LOW);
delay(0);
digitalWrite(led2, LOW);
delay(0);
int sensorReading = analogRead(0);
if (sensorReading > threshold) {
tone(8, NOTE_C4, 20);
tone(8, NOTE_D4, 20);
}
}
}
}