/
attiny_charlieplexing.ino
66 lines (52 loc) · 1.23 KB
/
attiny_charlieplexing.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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
/*
Vcc D2 D1 D0
----------------------------
8 7 6 5
1 2 3 4
----------------------------
D3 D4 Gnd
*/
#define TOTAL_PINS 4
#define TOTAL_STATES 12
byte pinNumber[TOTAL_PINS] = {2, 4, 1, 3};
int pinState[TOTAL_STATES][TOTAL_PINS] = {
{ -1, LOW, HIGH, -1},
{ -1, HIGH, LOW, -1},
{HIGH, LOW, -1, -1},
{LOW, HIGH, -1, -1},
{HIGH, -1, LOW, -1},
{LOW, -1, HIGH, -1},
{HIGH, -1, -1, LOW},
{LOW, -1, -1, HIGH},
{ -1, HIGH, -1, LOW},
{ -1, LOW, -1, HIGH},
{ -1, -1, HIGH, LOW},
{ -1, -1, LOW, HIGH},
};
int led = 0;
void setup() {
//Using this loop is 30 bytes worse than unfolding it
for (int f = 0; f <= TOTAL_PINS; f++) {
pinMode(pinNumber[f], OUTPUT);
}
}
void loop() {
//Using this loop is 84 bytes worse than unfolding it
for (int f = 0; f <= TOTAL_PINS; f++) {
// digitalWrite(pins[f], HIGH);
// delay(15);
// digitalWrite(pins[f], LOW);
// delay(85);
if (pinState[led][f] == -1) {
pinMode(pinNumber[f], INPUT);
} else {
pinMode(pinNumber[f], OUTPUT);
digitalWrite(pinNumber[f], pinState[led][f]);
}
}
led++;
if (led >= TOTAL_STATES) {
led = 0;
}
delay(10);
}