IR Remote Demonstration
Final code used:
/*
* IRremote: IRrecvDemo - demonstrates receiving IR codes with IRrecv
* An IR detector/demodulator must be connected to the input RECV_PIN.
* Version 0.1 July, 2009
* Copyright 2009 Ken Shirriff
* http://arcfn.com
*/
//IR code:
#include <IRremote.h>
const int RECV_PIN = 11;
IRrecv irrecv(RECV_PIN);
decode_results results;
//Servo Code
#include <Servo.h>
Servo servoA;
Servo servoB;
//const int servospeedA = 81 /*Check value */; //roughly mid value in 0-180 should be no motion
//const int servospeedB = 86 /*Check value */; //roughly mid value in 0-180 should be no motion
void setup()
{
Serial.begin(9600);
//Servo Code:
servoA.attach(9);
servoB.attach(10);
//servoA.write(81);
//servoB.write(85);
//IR Code:
irrecv.enableIRIn(); // Start the receiver
}//end void setup
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
irrecv.resume(); // Receive the next value
}
//Servo code:
if(results.value == 551485695){
servoA.write(81);
delay(100);
servoA.write(0);
delay(50);
}
if(results.value == 551518335){
servoA.write(81);
delay(100);
servoA.write(180);
delay(50);
}
if(results.value == 551499975){
servoA.write(81);
}
if(results.value == 551502015){
servoB.write(90);
delay(100);
servoB.write(0);
delay(50);
}
if(results.value == 551534655){
servoB.write(90);
delay(100);
servoB.write(180);
delay(50);
}
if(results.value == 551506605){
servoB.write(90);
}
//end if statement
/*if("(channel down) IR value is min"){
servoA.write(0);
}//end if statement
else(servoA.write(81));
if statements controlling the motorspeeds need specifics on how to obtain high or low
(up or down channel or volume signal) in order to write forward or backward speed to servo
correctly.
if("(volume up) IR value is max"){
servoB.write(180);
}//end if statement
if("(volume down) IR value is min"){
servoB.write(0);
}//end if statement
else(servoB.write(86));
*/
}//end void loop
No comments:
Post a Comment