Skip to content

Instantly share code, notes, and snippets.

@AiHiro
Created February 6, 2017 13:23
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/6448d9db30ed77eca3e9463491285615 to your computer and use it in GitHub Desktop.
Save AiHiro/6448d9db30ed77eca3e9463491285615 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; // define A0 port to receive control signal from potentiometer
int position; // variable to read the value from the analog pin
int infrared = 10; //remote digital pin
long plus = 0xFFA857;
long minus = 0xFFE01F;
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()
{
//position = map(analogRead(control_put), 0, 1023, 0, 179); //get input signal from A0,convert it into angle value
//servo_obj.write(position); // sets the servo position according to the scaled value
//delay(25);
if (irrecv.decode(&signals)) {
Serial.println(signals.value, HEX);
irrecv.resume(); // get the next signal
if(signals.value == plus) {
i += 30;
servo_obj.write(i);
if(i>= 180){
i = 0;
}
}else if(signals.value == minus){
i -= 30;
servo_obj.write(i);
if(i<= 0){
i = 180;
}
}
}
delay(25);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment