Last active
June 12, 2017 13:23
-
-
Save lbattaglioli2000/790b500646583c98f651296efbcbbdec to your computer and use it in GitHub Desktop.
Receiving
This file contains hidden or 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 <IRremote.h> | |
#include <string.h> | |
#include <Servo.h> | |
Servo leftServo; | |
Servo rightServo; | |
int RECV_PIN = 5; | |
IRrecv irrecv(RECV_PIN); | |
decode_results results; | |
void setup() | |
{ | |
Serial.begin(9600); | |
// Set servos to their pins | |
leftServo.attach(11); | |
rightServo.attach(10); | |
// In case the interrupt driver crashes on setup, give a clue | |
// to the user what's going on. | |
Serial.println("Enabling IRin"); | |
irrecv.enableIRIn(); // Start the receiver | |
Serial.println("Enabled IRin"); | |
} | |
// Function Declarations | |
void turn() { | |
Serial.println("Turn..."); | |
leftServo.write(90); | |
rightServo.write(180); | |
} | |
void straight(){ | |
Serial.println("Straight"); | |
leftServo.write(135); | |
rightServo.write(30); | |
} | |
void check(){ | |
if (irrecv.decode(&results)) { | |
Serial.println(results.value, HEX); | |
if(((results.value) == 0x29A, HEX) || ((results.value, HEX) == 0xFFFFFF) || ((results.value) == 666)){ | |
straight(); | |
} | |
}else{ | |
turn(); | |
} | |
irrecv.resume(); // Receive the next value | |
delay(100); | |
} | |
void loop() { | |
check(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment