So, what the code is suppose todo is read the ir hex after 2 seconds of setup(), and set yes to the returned value.
Then in loop check if a ir value has been received and ifso high a pin and low a pin.
But when i hit the button of my remote it will light up the led attached.
If i hit a different button it still lights up the led attached?
It for somewhat reason continiously setting yes to a new ir value.
I would love some guidance!
#include <IRremote.h>
const int toggle_pin = 2;
const int RECV_PIN = 1;
IRrecv irrecv(RECV_PIN);
decode_results results;
String yes = "";//button we want!
boolean set = true;
void setup()
{
pinMode(toggle_pin,OUTPUT);
pinMode(RECV_PIN,INPUT);
irrecv.enableIRIn(); // Start the receiver
delay(2000);
if(set){
if (irrecv.decode(&results)) {
yes = String(results.value,HEX);
set = false;
irrecv.resume();
}
}
digitalWrite(toggle_pin,HIGH);
delay(250);
digitalWrite(toggle_pin,LOW);
}
void loop() {
if (irrecv.decode(&results)) {
if(String(results.value,HEX) == yes){
//AKA correct button pressed
digitalWrite(toggle_pin,HIGH);
delay(250);
digitalWrite(toggle_pin,LOW);
}
irrecv.resume(); // Receive the next value
}
delay(250);
}
So, i might of should have been more clear. So this was on a ATtiny and i have tried it without the yes check, it worked!. I used an actual arduino to check the IR value from my remote but the ir library for attiny is different from the normal arduino and i think the values are different from each other even while using a long value.
/*
* 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
*/
#include <IRremote.h>
const int toggle_pin = 2;
const int RECV_PIN = 1;
IRrecv irrecv(RECV_PIN);
decode_results results;
unsigned long yes = 0;//button we want!
void setup()
{
pinMode(toggle_pin,OUTPUT);
pinMode(RECV_PIN,INPUT);
irrecv.enableIRIn(); // Start the receiver
digitalWrite(toggle_pin,HIGH);
delay(250);
digitalWrite(toggle_pin,LOW);
}
void loop() {
if (irrecv.decode(&results)) {
if(yes == 0){
yes = results.value;
//aka set new value!
digitalWrite(toggle_pin,HIGH);
delay(100);
digitalWrite(toggle_pin,LOW);
delay(100);
digitalWrite(toggle_pin,HIGH);
delay(100);
digitalWrite(toggle_pin,LOW);
}else if(results.value == yes){
//AKA correct button pressed
digitalWrite(toggle_pin,HIGH);
delay(250);
digitalWrite(toggle_pin,LOW);
}
irrecv.resume(); // Receive the next value
}
delay(250);
}
So this will constantly set the value even tho yes is no longer 0? IDK why its doing this...
It constantly runs the on/off-on/off instead of it running once and from there on only run the on/off
Apperently, the ir library returns 0 to all values except NEC repeat. I really dont know what todo anymore...I have tried 2 different attinies too but no result.