User manual

Upload the sketch and try pushing the left and right arrow buttons. The servo should turn left and
right. Pushing the enter button should center the servo. Pushing the up or down arrow buttons will
not have any visible effect but it will change the speed of movement you push left or right. The
numbered buttons from zero through nine move the servo to 10 different fixed positions at 2
intervals.
If the servo behaves erratically, it may be a power supply problem. Some USB ports do not deliver
sufficient current to drive the Arduino and move the servo. You may need to add an external 5 volt
supply. Here is a video demonstrating this example.
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;
switch(My_Decoder.value) {
case LEFT_ARROW: pos=min(180,pos+Speed); break;
case RIGHT_ARROW: pos=max(0,pos-Speed); break;
case SELECT_BUTTON: pos=90; break;
case UP_ARROW: Speed=min(10, Speed+1); break;
case DOWN_ARROW: Speed=max(1, Speed-1); break;
case BUTTON_0: pos=0*20; break;
case BUTTON_1: pos=1*20; break;
case BUTTON_2: pos=2*20; break;
case BUTTON_3: pos=3*20; break;
case BUTTON_4: pos=4*20; break;
case BUTTON_5: pos=5*20; break;
case BUTTON_6: pos=6*20; break;
case BUTTON_7: pos=7*20; break;
case BUTTON_8: pos=8*20; break;
case BUTTON_9: pos=9*20; break;
}
My_Servo.write(pos); // tell servo to go to position in variable 'pos'
Previous=My_Decoder.value;
}
My_Receiver.resume();
}
}
NOTE: If using Leonardo, Micro, or Yun or other ATmega32u4 System, See the special
instructions at the end of this page.
© Adafruit Industries https://learn.adafruit.com/using-an-infrared-library Page 16 of 23