Greetings,
I just managed to get something to work, and I thought it might be useful to the community, so I thought I'd post it.
I am trying to build a simple blinky LED to emulate the beacon light at the top of a TARDIS. Getting the light to blink is easy enough. The only trouble I was having was getting it to blink on cue. I didn't want to run wires from the trigger button to the arduino (actually an attiny85). I couldn't use IR since line-of-sight would be difficult to achieve. So I bought a really simple radio TX/RX pair from dealextreme:
I figured I'd wire the receiver into a pin on the attiny85 LED blinker, and wire the transmitter to its own 5V supply with a clicky-button between Vcc and its data line.
At first I got a bunch of noise on the attiny85. But I discovered that the receiver can pick up button transitions really well. So I wrote the following code:
void waitForPress(byte pin) {
byte reading[5];
reading[4] = reading[3] = reading[2] = reading[1] = reading[0] = 0;do {
reading[0] = 0;
for(byte i = 10; i > 0; --i) {
reading[0] += digitalRead(pin);
delay(1);
}
for(byte i = 4; i > 0; --i) {
reading* = reading[i - 1];*
- }*
- }*
- while(reading[0] != 0 || reading[4] != 10);*
}
[/quote]
In essence, this code takes digitalReadings from the pin tied to the receiver at 1ms intervals. It sums them together in groups of ten. We keep track of the sums for the five most recent groups, and if the most recent group is a zero, and the oldest group is a ten, then the button was pressed. Its sort of the ultimate switch debounce with edge detection.
Anyway, I thought I'd mention it. It was useful in my case, and I thought others in need of a simple remote button for the arduino might find it useful also.
Cheers,
Peter.