1 #include <avr/pgmspace.h>
3 #ifdef __AVR_ATtiny85__
4 static const byte NW_pin = 3;
5 static const byte NE_pin = 4;
6 static const byte SE_pin = 1;
7 static const byte SW_pin = 0;
9 static const byte NW_pin = 5;
10 static const byte NE_pin = 6;
11 static const byte SE_pin = 10;
12 static const byte SW_pin = 11;
15 static const byte MAX_STEPS=11;
16 static const unsigned long pattern[][MAX_STEPS] PROGMEM =
18 { 0xFFFF0000, 0, 0xFFFF0000, 0, 0xFFFF0000, 0, 0xFFFF0000},
19 { 0x0000FFFF, 0, 0x0000FFFF, 0, 0x0000FFFF, 0, 0x0000FFFF},
20 { 0xFFFF0000, 0, 0xFFFF0000, 0, 0xFFFF0000, 0, 0xFFFF0000},
21 { 0x0000FFFF, 0, 0x0000FFFF, 0, 0x0000FFFF, 0, 0x0000FFFF},
22 { 0xFFFF0000, 0, 0xFFFF0000, 0, 0xFFFF0000, 0, 0xFFFF0000},
23 { 0x0000FFFF, 0, 0x0000FFFF, 0, 0x0000FFFF, 0, 0x0000FFFF},
24 { 0xff000000, 0xffff0000, 0x00ffff00, 0x0000ffff, 0x000000ff, 0},
25 { 0xff000000, 0xffff0000, 0x00ffff00, 0x0000ffff, 0x000000ff, 0},
26 { 0xff000000, 0xffff0000, 0x00ffff00, 0x0000ffff, 0x000000ff, 0},
27 { 0, 0x1010, 0x1010, 0x2020, 0x2020, 0x4040, 0x4040, 0x8080, 0x8080, 0xffff, 0xffff },
28 { 0, 0x1010, 0x1010, 0x2020, 0x2020, 0x4040, 0x4040, 0x8080, 0x8080, 0xffff, 0xffff },
29 { 0, 0x1010, 0x1010, 0x2020, 0x2020, 0x4040, 0x4040, 0x8080, 0x8080, 0xffff, 0xffff },
30 { 0, 0x10100000, 0x10100000, 0x20200000, 0x20200000, 0x40400000, 0x40400000, 0x80800000, 0x80800000, 0xffff0000, 0xffff0000 },
31 { 0, 0x10100000, 0x10100000, 0x20200000, 0x20200000, 0x40400000, 0x40400000, 0x80800000, 0x80800000, 0xffff0000, 0xffff0000 },
32 { 0, 0x10100000, 0x10100000, 0x20200000, 0x20200000, 0x40400000, 0x40400000, 0x80800000, 0x80800000, 0xffff0000, 0xffff0000 },
34 static const byte NUM_PATTERNS = sizeof(pattern) / sizeof(pattern[0]);
36 static byte current = 0, step = 0;
40 pinMode(NW_pin, OUTPUT);
41 pinMode(NE_pin, OUTPUT);
42 pinMode(SE_pin, OUTPUT);
43 pinMode(SW_pin, OUTPUT);
55 blink(NW_pin, 200, 200);
57 blink(NE_pin, 200, 200);
59 blink(SE_pin, 200, 200);
61 blink(SW_pin, 200, 200);
66 fadeUp(NW_pin, 0, 255, 50);
67 fadeUp(SW_pin, 0, 255, 50);
68 fadeUp(SE_pin, 0, 255, 50);
69 fadeUp(NE_pin, 0, 255, 50);
71 fadeDown(NE_pin, 255, 0, 50);
72 fadeDown(SE_pin, 255, 0, 50);
73 fadeDown(SW_pin, 255, 0, 50);
74 fadeDown(NW_pin, 255, 0, 50);
77 void blink(byte pin, unsigned long lightMillis, unsigned long pauseMillis) {
87 void fadeUp(byte pin, byte from, byte to, unsigned long pauseMillis)
92 for(byte val=from; val<to; val+=step)
94 analogWrite(pin, val);
99 void fadeDown(byte pin, byte from, byte to, unsigned long pauseMillis)
101 if (to>=from) return;
104 for(byte val=from; val>to; val-=step)
106 analogWrite(pin, val);
113 long lVal = pgm_read_dword(&pattern[current][step]);
114 byte const *b = reinterpret_cast<byte const *>(&lVal);
115 analogWrite(NW_pin, b[0]);
116 analogWrite(NE_pin, b[1]);
117 analogWrite(SE_pin, b[2]);
118 analogWrite(SW_pin, b[3]);
125 if (current == NUM_PATTERNS)