forked from sweetpi/attiny-433mhz-sender
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.c
executable file
·53 lines (40 loc) · 956 Bytes
/
main.c
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
50
51
52
#include <avr/io.h>
#include <avr/interrupt.h>
#include <util/delay.h>
#include <avr/sleep.h>
#define TRANS_PIN PB2
#include "rc.h"
#define INPUT_PIN0 PB0
#define INPUT_PIN1 PB1
#define SWITCH_ID "100010100111100010011010"
volatile char state;
int main(void) {
// Configure TRANS_PIN as output
DDRB |= (1 << TRANS_PIN);
// Set INPUT_PIN as Input
DDRB &= ~(1 << INPUT_PIN0 | 1 << INPUT_PIN1);
// Enable PCINT0 (PB0) and PCINT1 (PB1) interrupt
PCMSK |= (1<<PCINT0 | 1<<PCINT1);
// turn on interrupts!
GIMSK |= (1<<PCIE);
sei();
// Set TRANS_PIN low
PORTB &= ~(1 << TRANS_PIN);
while (1) {
// in den Schlafmodus wechseln
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_mode();
// debounce:
_delay_ms(200);
// send(id, oneOrAll, onOrOff, unit):
send(SWITCH_ID, 1, state, "1");
}
}
ISR (PCINT0_vect)
{
if( !(PINB & (1 << INPUT_PIN0)) ) {
state = 1;
} else if ( !(PINB & (1 << INPUT_PIN1)) ) {
state = 0;
}
}