Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <IRremote.h> //must copy IRremote library to arduino libraries
- #include <Servo.h>
- #define left1 0xE17AD827 //clockwise rotation button
- #define right1 0xE17A38C7 //counter clockwise rotation button
- #define left2 0xE17AD02F //clockwise rotation button
- #define right2 0xE17A30CF //counter clockwise rotation button
- int RECV_PIN = 2; //IR receiver pin
- Servo servo1;
- Servo servo2;
- int val1; //rotation angle
- int val2; //rotation angle
- bool cwRotation1, ccwRotation1; //the states of rotation
- bool cwRotation2, ccwRotation2; //the states of rotation
- IRrecv irrecv(RECV_PIN);
- decode_results results;
- //--------------------------
- void setup()
- {
- Serial.begin(9600);
- irrecv.enableIRIn(); // Start the receiver
- servo1.attach(9); //servo pin
- servo2.attach(10); //servo pin
- }
- //---------------------------
- void loop()
- {
- if (irrecv.decode(&results))
- {
- Serial.println(results.value, HEX);
- irrecv.resume(); // Receive the next value
- motor1();
- motor2();
- }
- }
- //----------------------------
- void motor1()
- {
- if (results.value == left1)
- {
- cwRotation1 = !cwRotation1; //toggle the rotation value
- ccwRotation1 = false; //no rotation in this direction
- }
- if (results.value == right1)
- {
- ccwRotation1 = !ccwRotation1; //toggle the rotation value
- cwRotation1 = false; //no rotation in this direction
- }
- if (cwRotation1 && (val1 != 175))
- {
- val1++; //for colockwise button
- }
- if (ccwRotation1 && (val1 != 0))
- {
- val1--; //for counter colockwise button
- }
- servo1.write(val1);
- delay(20); //General speed
- }
- //----------------------------
- void motor2()
- {
- if (results.value == left2)
- {
- cwRotation2 = !cwRotation2; //toggle the rotation value
- ccwRotation2 = false; //no rotation in this direction
- }
- if (results.value == right2)
- {
- ccwRotation2 = !ccwRotation2; //toggle the rotation value
- cwRotation2 = false; //no rotation in this direction
- }
- if (cwRotation2 && (val2 != 175))
- {
- val2++; //for colockwise button
- }
- if (ccwRotation2 && (val2 != 0))
- {
- val2--; //for counter colockwise button
- }
- servo2.write(val2);
- delay(20); //General speed
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement