Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <IRremote.h>
- #define irPin 11
- #define go_time 1000
- #define turn_time 200
- #define motor_left_A 2
- #define motor_left_B 3
- #define motor_right_A 4
- #define motor_right_B 5
- IRrecv irrecv(irPin);
- decode_results results;
- void setup() {
- Serial.begin(9600);
- irrecv.enableIRIn();
- pinMode(motor_left_A, OUTPUT);
- pinMode(motor_left_B, OUTPUT);
- pinMode(motor_right_A, OUTPUT);
- pinMode(motor_right_B, OUTPUT);
- }
- void go() {
- digitalWrite(motor_left_A, LOW);
- digitalWrite(motor_left_B, HIGH);
- digitalWrite(motor_right_A, LOW);
- digitalWrite(motor_right_B, HIGH);
- delay(go_time);
- stop();
- }
- void back() {
- digitalWrite(motor_left_A, HIGH);
- digitalWrite(motor_left_B, LOW);
- digitalWrite(motor_right_A, HIGH);
- digitalWrite(motor_right_B, LOW);
- delay(go_time);
- stop();
- }
- void left() {
- digitalWrite(motor_left_A, LOW);
- digitalWrite(motor_left_B, HIGH);
- digitalWrite(motor_right_A, HIGH);
- digitalWrite(motor_right_B, LOW);
- delay(turn_time);
- stop();
- }
- void right() {
- digitalWrite(motor_left_A, HIGH);
- digitalWrite(motor_left_B, LOW);
- digitalWrite(motor_right_A, LOW);
- digitalWrite(motor_right_B, HIGH);
- delay(turn_time);
- stop();
- }
- void stop() {
- digitalWrite(motor_left_A, LOW);
- digitalWrite(motor_left_B, LOW);
- digitalWrite(motor_right_A, LOW);
- digitalWrite(motor_right_B, LOW);
- }
- void loop() {
- Serial.print("0x");
- Serial.println(results.value, HEX);
- delay(250);
- if (irrecv.decode(&results)) {
- // dol
- switch (results.value) {
- case 0x2FDF807 :
- back();
- break;
- }
- // gora
- switch (results.value) {
- case 0x2FDD827 :
- go();
- break;
- }
- // lewo
- switch (results.value) {
- case 0x2FD58A7 :
- left();
- break;
- }
- //prawo
- switch (results.value) {
- case 0x2FD7887 :
- right();
- break;
- }
- //stop
- switch (results.value) {
- case 0x2FD48B7 :
- stop();
- break;
- }
- irrecv.resume();
- }
- }
Add Comment
Please, Sign In to add comment