I came across an led puzzle box project today which i thought looked really good and got it working first time with no issues, I'm trying to add a buzzer to the code which plays at the end when all led's are lit but no matter how i try to write the code in I get similar error messages and i cant work out what I'm missing ( I know its something simple like a comma or a bracket in the wrong place but i now cant see for looking).
if anyone can help it would be greatly appreciated as I've scoured the web and come up with nothing.
error code...
Arduino: 1.8.13 (Windows 10), TD: 1.53, Board: "Arduino Uno"
C:\Users\duncan\Documents\Arduino\ledpuzzlewith_buzzer\ledpuzzlewith_buzzer.ino: In function 'void toggle3(int, int, int)':
ledpuzzlewith_buzzer:130:19: error: expected primary-expression before ']' token
if (LED_State[] = ){0, 1,1,1,1,1,1}; //d
^
ledpuzzlewith_buzzer:130:23: error: expected primary-expression before ')' token
if (LED_State[] = ){0, 1,1,1,1,1,1}; //d
^
ledpuzzlewith_buzzer:130:39: error: expected ';' before '}' token
if (LED_State[] = ){0, 1,1,1,1,1,1}; //d
^
ledpuzzlewith_buzzer:131:19: error: 'thisNote' was not declared in this scope
tone(11, melody[thisNote], duration); //d
^~~~~~~~
ledpuzzlewith_buzzer:134:3: error: 'else' without a previous 'if'
else
^~~~
exit status 1
expected primary-expression before ']' token
#include <IRremote.h> //Infrared Remote Library
#include "pitches.h" // For Passive Buzzer (dunk)
int RECV_PIN = 12;
IRrecv irrecv(RECV_PIN); //Setup the IR remote for initilisation
decode_results results; // set a decode variable, called results
const int LED [] = {0, 7, 6, 5, 4, 3}; // Set LED's as Digital Pins 7 thru 3
const int buzzer = 11; //(dunk)
int LED_State[] = {0, 0, 0, 0, 0, 0, 0}; // Inlcude one more than the number of LED's
// you have, first val must be zero. Sets all
// LED's to low/off
int melody[] = {
NOTE_C5, NOTE_D5, NOTE_E5, NOTE_F5, NOTE_G5, NOTE_A5, NOTE_B5, NOTE_C6};
int duration = 500; // 500 miliseconds // tones for buzzer (dunk)
unsigned int val = 0; // A variable to store the IR reading
const int code1 = 12495; //Set the values recieved
const int code2 = 6375; //from the IR remote
const int code3 = 31365; //for your chosen buttons
const int code4 = 4335;
const int code5 = 14535;
const int code6 = 41565; //all leds off (dunk)
void setup() {
Serial.begin(9600); // Turn on to allow you to check your IR remote values
irrecv.enableIRIn(); // Start the IR receiver
for (int i = 1; i < 6; i++) { // Set all LED's as OUTPUTS
pinMode(LED[i], OUTPUT);
pinMode(buzzer,OUTPUT);
}
}
void loop() {
if (irrecv.decode(&results)) { //If the IR receiver gets a signal
val = results.value; //Save that signal as a value to 'val'
Serial.println(val); //To check the values from your remote
switch (val) {
case code1: //If the IR reciever picks up code1
toggle2(1, 4); //Toggle these LED's on/off
break;
case code2: //If the IR reciever picks up code2
toggle2(2, 3); //Toggle these LED's on/off
break;
case code3: //If the IR reciever picks up code3
toggle3(3, 4, 5); //Toggle these LED's on/off
break;
case code4: //If the IR reciever picks up code4
toggle3(1, 4, 5); //Toggle these LED's on/off
break;
case code5: //If the IR reciever picks up code5
toggle3(1, 3, 4); //Toggle these LED's on/off
break ;
case code6 :
for (int i = 1; i < 6; i++) { // If Code 6 is received, all LED's are
digitalWrite(LED[i], LOW); // turned off
LED_State[i] = 0;
}
break ;
}
irrecv.resume(); // Recieve the Next value
}
}
//Create a function to toggle two LED's on/off
void toggle2(int x, int y) { //Set x and y as two of the LED's (mix it up!)
if (LED_State[x] == 0) { //check to see if LED is currently on low/off
digitalWrite(LED[x], HIGH); // if its off, turn it on
LED_State[x] = 1;
} else {
digitalWrite(LED[x], LOW); // if its on, turn it off
LED_State[x] = 0;
}
if (LED_State[y] == 0) { //check to see if LED is currently on low/off
digitalWrite(LED[y], HIGH); // if its off, turn it on
LED_State[y] = 1;
} else {
digitalWrite(LED[y], LOW); // if its on, turn it off
LED_State[y] = 0;
}
}
//Create a function to toggle three LED's on/off
void toggle3(int x, int y, int z) { //Set x and y as two of the LED's (mix it up!)
if (LED_State[x] == 0) { //check to see if LED is currently on low/off
digitalWrite(LED[x], HIGH); // if its off, turn it on
LED_State[x] = 1;
} else {
digitalWrite(LED[x], LOW); // if its on, turn it off
LED_State[x] = 0;
}
if (LED_State[y] == 0) { //check to see if LED is currently on low/off
digitalWrite(LED[y], HIGH); // if its off, turn it on
LED_State[y] = 1;
} else {
digitalWrite(LED[y], LOW); // if its on, turn it off
LED_State[y] = 0;
}
if (LED_State[z] == 0) { //check to see if LED is currently on low/off
digitalWrite(LED[z], HIGH); // if its off, turn it on
LED_State[z] = 1;
} else {
digitalWrite(LED[z], LOW); // if its on, turn it off
LED_State[z] = 0;
} if {
(LED_State[] = ){0, 1,1,1,1,1,1}; //d
tone(11, melody[thisNote], duration); //d
delay(1000); //(dunk)
}
else
{
noTone(11);
}
}