Created
February 7, 2017 13:03
-
-
Save AiHiro/56b7c6c49ac591685c883c5f00ce691c to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#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