forked from nro-bot/pov-yoyo
-
Notifications
You must be signed in to change notification settings - Fork 0
/
v0.1.45.c
168 lines (152 loc) · 2.86 KB
/
v0.1.45.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
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
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// attiny45
// 6 LEDs charlieplexed on pins 5, 6, 7
// button on pin 3
// phototransistor on pin 2 (w/ 49.9kohm)
// Vcc = 3V
#include <avr/io.h>
#include <util/delay.h>
#define led_delay() _delay_us(2000) // LED delay
#define LINE_A 0
#define LINE_B 1
#define LINE_C 2
#define IMGLEN 55
//~ #define B3(x) ((x&0b00000001)?0:0) \
//~ +((x&0b00000010)?2:0) \
//~ #define B5(x) ((x&0b00000001)?0:0) \
//~ +((x&0b00000010)?1:0) \
//~ +((x&0b00000100)?2:0) \
//~ +((x&0b00001000)?3:0) \
//~ +((x&0b00010000)?4:0) \
//~ +((x&0b00010000)?5:0) \
//DDRB direction config for each LED (1 = output) //i/o
const char led_dir[6] = {
( 1<<LINE_B | 1<<LINE_A & ~(1<<LINE_C)), //LED 0
( 1<<LINE_A | 1<<LINE_B & ~(1<<LINE_C)), //LED 1
( 1<<LINE_C | 1<<LINE_B & ~(1<<LINE_A)), //LED 2
( 1<<LINE_B | 1<<LINE_C & ~(1<<LINE_A)), //LED 3
( 1<<LINE_A | 1<<LINE_C & ~(1<<LINE_B)), //LED 4
( 1<<LINE_C | 1<<LINE_A & ~(1<<LINE_B)), //LED 5
};
//PORTB output config for each LED (1 = High, 0 = Low) //hi/lo
const char led_out[6] = {
( 1<<LINE_B & ~(1<<LINE_A)), //LED 0
( 1<<LINE_A & ~(1<<LINE_B)), //LED 1
( 1<<LINE_C & ~(1<<LINE_B)), //LED 2
( 1<<LINE_B & ~(1<<LINE_C)), //LED 3
( 1<<LINE_A & ~(1<<LINE_C)), //LED 4
( 1<<LINE_C & ~(1<<LINE_A)), //LED 5
};
void light_led(char led_num) { //led_num [0,5]
DDRB = led_dir[led_num];
PORTB = led_out[led_num];
_delay_us(20);
};
const static char bit[5] = {
0b00001,
0b00010,
0b00100,
0b01000,
0b10000,
};
void check_led(char bar, int i){
if (bar & bit[i]) { //which led to light up?
light_led(i);
}
else {
_delay_us(30);
}
};
void B5(char x) {
for(int j=0; j < 6; j++){
check_led(x,j);
};
};
//~ const static uint8_t image[4] = {
//~ B3(0b00),
//~ B3(0b10),
//~ B3(0b11),
//~ B3(0b00),
//~ };
const static char image[IMGLEN] = {
0b01110,
0b11111,
0b10001,
0b10001,
0b11111,
0b01110,
0b00000,
0b00000,
0b11111,
0b11111,
0b10000,
0b10000,
0b10000,
0b00000,
0b00000,
0b01110,
0b11111,
0b10001,
0b11111,
0b01110,
0b00000,
0b00000,
0b11111,
0b11111,
0b00101,
0b00111,
0b00010,
0b00000,
0b00000,
0b11111,
0b11111,
0b10101,
0b10101,
0b10001,
0b00000,
0b00000,
0b11111,
0b11111,
0b10001,
0b11011,
0b01110,
0b00000,
0b00000,
0b11111,
0b11111,
0b10101,
0b10101,
0b10001,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
0b00000,
};
//~ void light_leds(char led_state) { //led_state is on/off 1 bit per LED
//~ };
void leds_off() {
DDRB = 0;
PORTB = 0;
};
void flash_test() {
for(int x=0; x < 6; x++){
light_led(x);
_delay_ms(10);
}
};
int main(void) {
while (1) {
//~ flash_test();
//~ light_led(3);
for(int x = 0; x < IMGLEN; x++){
B5(image[x]);
leds_off();
_delay_us(200);
}
}
return 0;
}