Skip to content

Instantly share code, notes, and snippets.

@AiHiro
Created February 7, 2017 13:03
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AiHiro/56b7c6c49ac591685c883c5f00ce691c to your computer and use it in GitHub Desktop.
Save AiHiro/56b7c6c49ac591685c883c5f00ce691c to your computer and use it in GitHub Desktop.
#include <Servo.h>
#include <IRremote.h>
Servo servo_obj; // create servo object to control a servo
int control_put = 0;
int infrared = 10;
int position;
long plus = 0xFFA857;
long minus = 0xFFE01F;
const int max_angle = 180;
const int min_angle = 0;
IRrecv irrecv(infrared);
decode_results signals;
int i = 0;
void setup()
{
servo_obj.attach(7); // attaches the servo on pin 7 to the servo object
Serial.begin(9600);
irrecv.enableIRIn(); // enable input from IR receiver
}
void loop()
{
if (irrecv.decode(&signals)) {
Serial.println(signals.value, HEX);
irrecv.resume(); // get the next signal
if(signals.value == plus) {
if(i<max_angle){
i += max_angle;
servo_obj.write(i);
}
}else if(signals.value == minus){
if(i>min_angle){
i -= max_angle;
servo_obj.write(i);
}
}
}
delay(25);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment