0

I'm new to Arduinos and programming. I'm getting into a project and one of my tasks was to learn how to incorporate servos into Arduino and learn about sensors. I wanted to combine both, but I'm having some problems in my syntax. Can I get some help?

This is my code:

// servo test 
#include <Servo.h>
#include <IRremote.h>
#define START_BUTTON //place code for button // code recieved from start 
button
#define STOP_BUTTON //place code for button // code recieved from stop 
button
int servopin1 = 13; // first servo
int servopin2 = 12; // second servo
int pos = 0;
int receiver_pin = 4; // output pin 
int vcc = 5; // vcc ir sensor
int gnd = 6; // gnd for ir sensor
IRrecv receiver(receiver_pin);
decode_results output;
Servo Servo1;
Servo Servo2;
void setup() {
 // put your setup code here, to run once:
 Serial.begin(9600);
 receiver.enableIRIn();
 pinMode(vcc, OUTPUT);
 pinMode(gnd, OUTPUT);
 digitalWrite(vcc, HIGH);
 Servo1.attach(servopin1);
 Servo2.attach(servopin2); 
}
void loop() {
 // put your main code here, to run repeatedly:
 if (receiver.decode(&output)) {
 unsigned int value = output.value;
 switch(value) {
 case START_BUTTON:
 if (pos <= 180){
 Servo1.write(pos);
 delay(500);
 pos = pos + 30;} 
 else {
 pos=0;
 }
 if (pos <= 180){
 Servo2.write(pos);
 delay(500);
 pos = pos + 30;} 
 else {
 pos=0;}
 break;
 case STOP_BUTTON:
 Servo1.write(0);
 delay(200);
 Servo2.write(0);
 delay(200);
 break; 
 }
 }
 }
 //^servo 2 positions and delays
}

I'm trying to figure out why I'm getting a the following error:

C:\Users\Alex\Documents\Arduino\Servo_test2Library\Servo_test2Library.ino: 
In function 'void loop()':
Servo_test2Library:38: error: expected primary-expression before ':' token
 case START_BUTTON:
 ^
Servo_test2Library:53: error: expected primary-expression before ':' token
 case STOP_BUTTON:
 ^
C:\Users\Alex\Documents\Arduino\Servo_test2Library\Servo_test2Library.ino: 
At global scope:
Servo_test2Library:64: error: expected declaration before '}' token
 }
 ^
Multiple libraries were found for "IRremote.h"
 Used: C:\Users\Alex\Documents\Arduino\libraries\IRremote-2.2.3
 Not used: C:\Users\Alex\Documents\Arduino\libraries\Arduino-IRremote-master
Using library Servo at version 1.1.2 in folder: C:\Program Files 
(x86)\Arduino\libraries\Servo 
Using library IRremote-2.2.3 at version 2.2.3 in folder: 
C:\Users\Alex\Documents\Arduino\libraries\IRremote-2.2.3 
exit status 1
expected primary-expression before ':' token
Greenonline
3,1527 gold badges36 silver badges48 bronze badges
asked Aug 27, 2018 at 19:50

1 Answer 1

4

Up at the top of your code, you have:

#define START_BUTTON //place code for button // code recieved from start 
button
#define STOP_BUTTON //place code for button // code recieved from stop 
button

A #define needs 2 parts after it. The first is the new name being created, and the 2nd is the definition of the new name.

You should put the value that you expect for the START_BUTTON condition after the name, such as:

#define START_BUTTON 0x48
#define STOP_BUTTON 0x49

Or whatever your IR remote is sending.

Also, you have one too many closing braces (}) at the end.

 [...]
 case STOP_BUTTON:
 Servo1.write(0);
 delay(200);
 Servo2.write(0);
 delay(200);
 break; 
 } // THIS CLOSES THE SWITCH
 } // THIS CLOSES THE IF STATEMENT
 } // THIS CLOSES loop()
 //^servo 2 positions and delays
} // THIS IS NOT CLOSING ANYTHING THAT WAS OPENED
answered Aug 27, 2018 at 20:15

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.