My group and i have been having problems with our code and we cant figure out how to fix it. Could you help us? Thank you
This is the code
#include <IRremote.h>
#define code1 16712445 //code for forward button
#define code2 16769055 // code received from button LEFT
#define code3 16754775 // code received from button MIDDLE
#define code4 16748655 // code received from button RIGHT
int RECV_PIN = 11; //IR IS PLUGGED INTO PIN 11
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
irrecv.enableIRIn(); // Start the receiver
pinMode(7,OUTPUT); //MAKE PIN 7 AN OUTPUT
pinMode(6,OUTPUT); //MAKE PIN 6 AN OUTPUT
pinMode(5,OUTPUT); //MAKE PIN 5 AN OUTPUT
pinMode(4,OUTPUT); //MAKE PIN 4 AN OUTPUT
}
void loop() {
if (irrecv.decode(&results)) {
unsigned int value = results.value;
switch(value) {
if (== (case code1):
digitalWrite(7,HIGH); //both motors are turned on to push the boat forward
digitalWrite(6,LOW);
digitalWrite(5,HIGH); //ON
digitalWrite(4,LOW);
break;
else if (== (case code2):
digitalWrite(7,HIGH); //only the right motor is turned on to make the boat turn left
digitalWrite(6,LOW);
digitalWrite(5,LOW); //OFF
digitalWrite(4,LOW);
break;
else if (== (case code4):
digitalWrite(7,LOW); //OFF
digitalWrite(6,LOW);
digitalWrite(5,HIGH); //only the left motor is turned on to make the boat turn right
digitalWrite(4,LOW);
break;
else if (== (case code3):
digitalWrite(7,LOW); //all motors are turned off to make the boat stop moving
digitalWrite(6,LOW);
digitalWrite(5,LOW); //OFF
digitalWrite(4,LOW);
}
irrecv.resume(); // Receive the next value
}
}
And here are all the error messages
Arduino: 1.6.8 (Windows 10), Board: "Arduino/Genuino Uno"
C:\Users\Cuirithir\Desktop\full_sketch1\full_sketch1.ino: In function 'void loop()':
full_sketch1:38: error: expected primary-expression before '==' token
if (== (case code1):
^
full_sketch1:38: error: expected primary-expression before 'case'
if (== (case code1):
^
full_sketch1:38: error: expected ')' before 'case'
full_sketch1:40: error: expected ')' before ';' token
digitalWrite(7,HIGH); //both motors are turned on to push the boat forward
^
full_sketch1:48: error: expected '}' before 'else'
else if (== (case code2):
^
full_sketch1:48: error: expected '}' before 'else'
full_sketch1:48: error: expected primary-expression before '==' token
else if (== (case code2):
^
full_sketch1:48: error: expected primary-expression before 'case'
else if (== (case code2):
^
full_sketch1:48: error: expected ')' before 'case'
full_sketch1:50: error: expected ')' before ';' token
digitalWrite(7,HIGH); //only the right motor is turned on to make the boat turn left
^
full_sketch1:56: error: break statement not within loop or switch
break;
^
full_sketch1:57: error: 'else' without a previous 'if'
else if (== (case code4):
^
full_sketch1:57: error: expected primary-expression before '==' token
else if (== (case code4):
^
full_sketch1:57: error: expected primary-expression before 'case'
else if (== (case code4):
^
full_sketch1:57: error: expected ')' before 'case'
full_sketch1:59: error: expected ')' before ';' token
digitalWrite(7,LOW); //OFF
^
full_sketch1:65: error: break statement not within loop or switch
break;
^
full_sketch1:66: error: 'else' without a previous 'if'
else if (== (case code3):
^
full_sketch1:66: error: expected primary-expression before '==' token
else if (== (case code3):
^
full_sketch1:66: error: expected primary-expression before 'case'
else if (== (case code3):
^
full_sketch1:66: error: expected ')' before 'case'
full_sketch1:68: error: expected ')' before ';' token
digitalWrite(7,LOW); //all motors are turned off to make the boat stop moving
^
C:\Users\Cuirithir\Desktop\full_sketch1\full_sketch1.ino: At global scope:
full_sketch1:74: error: 'irrecv' does not name a type
irrecv.resume(); // Receive the next value
^
full_sketch1:76: error: expected declaration before '}' token
}
^
exit status 1
expected primary-expression before '==' token
This report would have more information with
"Show verbose output during compilation"
option enabled in File -> Preferences.