-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy patharc_reactor.ino
More file actions
103 lines (81 loc) · 2.19 KB
/
Copy patharc_reactor.ino
File metadata and controls
103 lines (81 loc) · 2.19 KB
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
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
/**
* Simple sketch to test how little power we can use when
* ATTiny goes to sleep.
* Most of the extra saving seems to be due to turning off ADC
**/
#include <avr/power.h>
#include <avr/sleep.h>
#ifdef __AVR_ATtiny85__
#define SWITCH_PIN 0
#define LED1_PIN 2
#define LED2_PIN 3
#define LED3_PIN 4
#else
#define SWITCH_PIN 2 // (interrupt 0)
#define LED_PIN 3
#endif
#define CYCLES 8
prog_uint16_t cycle_delays[CYCLES] PROGMEM = {
750, 500, 250, 200, 150, 50, 10, 10
};
void setup() {
pinMode(SWITCH_PIN, INPUT);
digitalWrite(SWITCH_PIN, HIGH);
pinMode(LED1_PIN, OUTPUT);
pinMode(LED2_PIN, OUTPUT);
pinMode(LED3_PIN, OUTPUT);
ADCSRA &= ~(1<<ADEN); //turn off ADC
ACSR |= _BV(ACD); //disable the analog comparator
}
void gotoSleep() {
#ifdef __AVR_ATtiny85__
GIMSK |= 1<<PCIE; //Enable Pin Change Interrupt
PCMSK |= 1<<PCINT0; //Watch for Pin Change on Pin5 (PB0)
#else
attachInterrupt(0, interrup, FALLING);
#endif
set_sleep_mode(SLEEP_MODE_PWR_DOWN);
sleep_enable();
sleep_mode();
// waking up from sleep mode.
sleep_disable();
#ifdef __AVR_ATtiny85__
GIMSK &= ~(1<<PCIE); //Disable the interrupt so it doesn't keep flagging
PCMSK &= ~(1<<PCINT0);
#else
detachInterrupt(0);
#endif
}
void cycle(int delayMillis) {
for ( int pin = LED1_PIN; pin <= LED3_PIN; pin++ ) {
digitalWrite(LED1_PIN, pin == LED1_PIN? HIGH : LOW);
digitalWrite(LED2_PIN, pin == LED2_PIN? HIGH : LOW);
digitalWrite(LED3_PIN, pin == LED3_PIN? HIGH : LOW);
delay(delayMillis);
}
}
void all(uint8_t state) {
digitalWrite(LED1_PIN, state);
digitalWrite(LED2_PIN, state);
digitalWrite(LED3_PIN, state);
}
void loop() {
gotoSleep();
// Wait for the button to be released
while (digitalRead(SWITCH_PIN) == LOW) { }
for ( int i = 0; i < CYCLES; i++ ) {
int delayMillis = 0xFFFF & pgm_read_word_near(cycle_delays + i);
cycle(delayMillis);
}
all(HIGH);
delay(5000);
for ( int i = CYCLES-1; i >= 0; i-- ) {
int delayMillis = 0xFFFF & pgm_read_word_near(cycle_delays + i);
cycle(delayMillis);
}
all(LOW);
}
void interrup() {}
// Interrupt for PIN0 falling edge
ISR(PCINT0_vect) {
}