Hi all-
Here’s what I am trying to do: I have an ATTiny85 receiving (via IR) a stream of ones sent at 5 Hz from another micro. The stream of ones is intermittent, as the IR receiver isn’t always pointed at the transmitter. In fact, orientation sensing of the receiver is what I’m after.
[incidentally, getting Software serial and IRrecv BOTH working at the same time was quite the adventure, but that’s another story!]
What I’d like to have happen is that a pin on the receiving end go HIGH as long as it’s seeing ones, and LOW if they stop coming. I have an LED on that pin to monitor its state, btw.
However, I don’t want the pin state to follow EVERY one/zero, which my code currently does, and which leads to a blinking LED. Seems like I need to ‘average’ the input over some small time interval, and set the pin accordingly. Having said that, though, and having tried a variety of schemes to make it work the solution still evades me. So I thought I’d ask if anyone has a nice hint for me!
Here’s my receive code at the moment:
#include "tiny_IRremote.h"
#include <SoftwareSerial.h>
int RECV_PIN = 1;
IRrecv irrecv(RECV_PIN);
decode_results results;
SoftwareSerial mySerial(3,2);
void setup(){
mySerial.begin(9600);
irrecv.enableIRIn();
pinMode(1, INPUT); // IR receive pin [physical pin 6]
pinMode(2, OUTPUT); // Serial TX pin [physical pin 7]
pinMode(0, OUTPUT); // LED output pin [physical pin 5]
}
void loop(){
if(irrecv.decode(&results)){
unsigned long value = results.value;
mySerial.print(value); // For testing purposes. Based on what
mySerial.print("\n"); // I see in the monitor, I know when/what characters
// are being received and that's all good.
if(value == 1){
digitalWrite(0, HIGH);
}
irrecv.enableIRIn();
}
digitalWrite(0, LOW);
}
Well, thanks in advance.
regards,
Patrick