0

My code keeps saying that that Button_8 and the rest of the #define macros are out of scope.

#include <IRLib.h>
#include <Servo.h>

#define MY_PROTOCOL SONY
#define RIGHT_ARROW   0xfd50af //Move several clockwise
#define LEFT_ARROW    0xfd10ef //Move servo counterclockwise
#define SELECT_BUTTON 0xfd906f //Center the servo
#define UP_ARROW      0xfda05f //Increased number of degrees servo 
#define DOWN_ARROW    0xfdb04f //Decrease number of degrees servo moves
#define BUTTON_0 0xfd30cf  //Pushing buttons 0-9 moves to fixed  positions
#define BUTTON_1 0xfd08f7  // each 20 degrees greater
#define BUTTON_2 0xfd8877
#define BUTTON_3 0xfd48b7
#define BUTTON_4 0xfd28d7
#define BUTTON_5 0xfda857
#define BUTTON_6 0xfd6897
#define BUTTON_7 0xfd18e7
#define BUTTON_8 0xfd9867
#define BUTTON_9 0xfd58a7

IRrecv My_Receiver(11);//Receive on pin 11
IRdecode My_Decoder; 
long Previous;
Servo myservo2;
Servo myservo;  


void setup() 
{
myservo.attach(8); 
myservo2.attach(3);
My_Receiver.enableIRIn();
}

void loop() 
{

  if (My_Receiver.GetResults(&My_Decoder))
{
   My_Decoder.decode();
   if(My_Decoder.decode_type==MY_PROTOCOL) 
   {
       if(My_Decoder.value==0xFFFFFFFF)
       My_Decoder.value= Previous;
       if(My_Decoder.value == Button_9)
       {
       myservo.write(0);
       myservo2.write(180);
       }
     else if(My_Decoder.value == Button_8)
      {
         myservo.write(180);
          myservo2.write(180);
       }


    }
}
}

when i use a switch statement instead of the 4 and 5 if statement like so:

switch(My_Decoder.value) {
        case Button_8:   //do something; break;

it works, but i dont know why.

2

C++ is case-sensitive. Button_8 is different from BUTTON_8.

| improve this answer | |

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.