I'm getting some confusing codes being received by my IR receiver.
I've hooked up IRRecvdemo from the IR library, and it works fine. I've found that the buttons that I want to use correspond to FD5AA5 and FDD827. If I hold down a button I get FFFFFFFF, but Google tells me that this is a repeat code, and normal.
OK so far.
I've adjusted the code to turn an LED on and off. Sweet! Works fine.
I added some more code to move a servo. It works sometimes. Which is really frustrating.
Sometimes the servo moves. But sometimes it doesn't. Serial monitor shows me that sometimes new button presses are being received as FFFFFFFF, which I haven't coded for anything, and even more confusingly, random HEX codes which are neither repeat codes nor command codes are being received (4AB0F7B7, 4CB0FADD).
#include <IRremote.h>
#include <Servo.h>
const int servoPin = 4;
Servo servo;
int RECV_PIN = 11;
int angle = 90;
int change = 5;
IRrecv irrecv(RECV_PIN);
decode_results results;
void setup()
{
Serial.begin(9600);
servo.attach(servoPin);
irrecv.enableIRIn(); // Start the receiver---
}
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
if (results.value==0xFD5AA5){//left button
digitalWrite(13,HIGH);
angle = angle + change;
}
if (results.value==0xFDD827){//this is the RIGHT button
digitalWrite(13,LOW);
angle = angle - change;
}
angle = constrain(angle, 10, 170);
servo.write(angle);
irrecv.resume(); // Receive the next value
}
//delay(100);
}
If I block out the parts to do with servo, the LEDs work fine. On with one button, off with the other.
void loop() {
if (irrecv.decode(&results)) {
Serial.println(results.value, HEX);
if (results.value==0xFD5AA5){//left button
digitalWrite(13,HIGH);
// angle = angle + change;
}
if (results.value==0xFDD827){//this is the RIGHT button
digitalWrite(13,LOW);
//angle = angle - change;
}
//angle = constrain(angle, 10, 170);
//servo.write(angle);
irrecv.resume(); // Receive the next value
}
//delay(100);
}
Please help. I think the servo is interacting strangely with something; I can get LEDs to blink with my remote but the servo ruining everything.