Skip to content

Instantly share code, notes, and snippets.

@lbattaglioli2000
Last active June 12, 2017 13:23
Show Gist options
  • Save lbattaglioli2000/790b500646583c98f651296efbcbbdec to your computer and use it in GitHub Desktop.
Save lbattaglioli2000/790b500646583c98f651296efbcbbdec to your computer and use it in GitHub Desktop.
Receiving
#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