/* Demo sketch unsing the IRremote.h library (see here for more info: http://www.righto.com/2009/08/multi-protocol-infrared-remote-library.html Modified by Rudy Schlaf 2/2014 for the Make Course: www.makecourse.com Again modified by Brandon Demers 2015 for Make Course project */ #include #include #include #include // Servo Library #define pin1 10 #define pin2 9 Servo servo1; // Servo control 1 Servo servo2; // Servo control 2 int RECV_PIN = 11; IRrecv irrecv(RECV_PIN);//instantiate a IR receiver object decode_results results;//instantiate a decode_results object. This object is separate from the IR receiver. LiquidCrystal_I2C lcd(0x27,16,2);//instantiate a 16x2 I2C LCD display with address 0x27 void setup() { Serial.begin(9600); lcd.init(); // initialize the lcd lcd.backlight(); irrecv.enableIRIn(); // Start the receiver servo1.attach(pin1); //"attach" servo to pin servo2.attach(pin2); //"attach" servo to pin int position; servo1.write(95); //Initialize Servo 1 servo2.write(95); //Initialize Servo 2 delay(100); } int UD = 95 ; //Initialize servo value in Up/Down direction int LR = 95 ; //Initialize servo value in Left/Rigth direction long p; // P is a longer number and requires more bits for enough accuracy to distinguish direction of prev. val. void loop() { if (irrecv.decode(&results)) { //has a transmission been received? Serial.println(results.value);//If yes: interpret the received commands... if (results.value == 16769055){ //If button is (-) p=16769055; //Set 'Previous' value for later if statement lcd.clear(); lcd.print("Rotate Left"); //Display the direction the servo is moving if(LR >= 30){ // If Servo has room to continue rotating left, keep going as button is pressed LR=LR-2; servo2.write(LR); Serial.print(LR); } } if (results.value == 16754775){ //If button is(+) p=16754775; //Set 'Previous' value for later if statement lcd.clear(); lcd.print("Rotate Right"); //Display the direction the servo is moving if(LR <= 160){ // If Servo has room to continue rotating right, keep going as button is pressed LR=LR+2; servo2.write(LR); Serial.print(LR); } } if (results.value == 16720605){ //If button is (<-) p=16720605; //Set 'Previous' value for later if statement lcd.clear(); lcd.print("Pivot Down"); //Display the direction the servo is moving if(UD >= 60){ // If Servo has room to continue rotating down, keep going as button is pressed UD=UD-1; servo1.write(UD); Serial.print(UD); } } if (results.value == 16712445){ // If button is (->) p=16712445; //Set 'Previous' value for later if statement lcd.clear(); lcd.print("Pivot Up"); // If Servo has room to continue rotating up, keep going as button is pressed if(UD<=130){ UD=UD+1; servo1.write(UD); } } // If statements to allow continuous movement until programmed stops reached if (p == 16769055 & results.value == 4294967295 & LR >= 60){ // If servo has room to go, and button is being held, rotate based on previous value LR=LR-2; servo2.write(LR); } if (p == 16754775 & results.value == 4294967295 & LR <= 130){ LR=LR+2; servo2.write(LR); } if (p == 16720605 & results.value == 4294967295 & UD >= 60){ UD=UD-1; servo1.write(UD); } if (p == 16712445 & results.value == 4294967295 & UD <= 130){ UD=UD+1; servo1.write(UD); } Serial.print(p); irrecv.resume(); // Receive the next value } }