forked from sui77/rc-switch
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathReceiveDemo_ATTinyInterrupts.ino
49 lines (38 loc) · 1.24 KB
/
ReceiveDemo_ATTinyInterrupts.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
/*
Simple example for receiving on ATTiny85 using pin change interrupt
This allows to connect receiver to literally any ATTiny pin
and not only INTO (PB2) imposed by mySwitch.enableReceive(0)
It makes sense because PB2 might not always be available.
For example it used as Serial TX with Digistump dtiny core
https://github.com/sui77/rc-switch/
*/
#include <RCSwitch.h>
#define RX_PIN PB0
RCSwitch mySwitch = RCSwitch();
void setupInterrupts() {
noInterrupts();
bitClear(GIMSK, INT0); // disable INT0 external interrupt
bitSet(GIMSK, PCIE); // enable pin change interrupt (PCI)
bitSet(PCMSK, RX_PIN); // activate PCI for the specific pin
interrupts();
}
void setup() {
Serial.begin(9600); // Serial TX for Digispark USB is on the PB2
setupInterrupts();
}
void loop() {
if (mySwitch.available()) {
Serial.print("Received ");
Serial.print( mySwitch.getReceivedValue() );
Serial.print(" / ");
Serial.print( mySwitch.getReceivedBitlength() );
Serial.print("bit ");
Serial.print("Protocol: ");
Serial.println( mySwitch.getReceivedProtocol() );
mySwitch.resetAvailable();
}
}
/*
* Interrupt handler
*/
ISR(PCINT0_vect) { RCSwitch::handleInterrupt(); } // handleInterrupt() must be public for that