-
Notifications
You must be signed in to change notification settings - Fork 0
/
jchillerup.c
187 lines (159 loc) · 2.87 KB
/
jchillerup.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
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include <util/delay.h>
#include <arduino/pins.h>
#include <arduino/serial.h>
#define LATCH 4
#define CLOCK 3
#define DATA 2
#define OE 8
#define RESET 9
#define MAX 255
#define MAX_R 50
#define MAX_G 100
#define MAX_B 100
#include "serial.c"
static uint8_t leds[48] = {
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0,
0, 0, 0
};
static uint8_t ledmask[] = {
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1
};
static void
shiftout(uint8_t v1, uint8_t v2, uint8_t v3,
uint8_t v4, uint8_t v5, uint8_t v6)
{
uint8_t mask;
pin_low(LATCH);
for (mask = 1; mask; mask <<= 1) {
if (v1 & mask)
pin_high(DATA);
else
pin_low(DATA);
pin_high(CLOCK);
pin_low(CLOCK);
}
for (mask = 1; mask; mask <<= 1) {
if (v2 & mask)
pin_high(DATA);
else
pin_low(DATA);
pin_high(CLOCK);
pin_low(CLOCK);
}
for (mask = 1; mask; mask <<= 1) {
if (v3 & mask)
pin_high(DATA);
else
pin_low(DATA);
pin_high(CLOCK);
pin_low(CLOCK);
}
for (mask = 1; mask; mask <<= 1) {
if (v4 & mask)
pin_high(DATA);
else
pin_low(DATA);
pin_high(CLOCK);
pin_low(CLOCK);
}
for (mask = 1; mask; mask <<= 1) {
if (v5 & mask)
pin_high(DATA);
else
pin_low(DATA);
pin_high(CLOCK);
pin_low(CLOCK);
}
for (mask = 1; mask; mask <<= 1) {
if (v6 & mask)
pin_high(DATA);
else
pin_low(DATA);
pin_high(CLOCK);
pin_low(CLOCK);
}
pin_high(LATCH);
}
static void
pwm() {
uint8_t i;
uint8_t v1 = 0xFF;
uint8_t v2 = 0xFF;
uint8_t v3 = 0xFF;
uint8_t v4 = 0xFF;
uint8_t v5 = 0xFF;
uint8_t v6 = 0xFF;
for (i = 0; i < MAX; i++) {
uint8_t mask;
uint8_t j = 0;
for (mask = 1; mask; mask <<= 1) {
if (i == leds[j])
v1 &= ~mask;
if (i == leds[j+8])
v2 &= ~mask;
if (i == leds[j+16])
v3 &= ~mask;
if (i == leds[j+24])
v4 &= ~mask;
if (i == leds[j+32])
v5 &= ~mask;
if (i == leds[j+40])
v6 &= ~mask;
j++;
}
shiftout(v1, v2, v3, v4, v5, v6);
}
}
int __attribute__((noreturn))
main()
{
uint8_t i;
/* initialize serial communication */
serial_init(9600, 8n1);
pin_mode_output(LATCH);
pin_mode_output(CLOCK);
pin_mode_output(DATA);
pin_mode_output(OE);
pin_mode_output(RESET);
pin_high(LATCH);
pin_low(CLOCK);
pin_high(DATA);
pin_low(OE);
pin_high(RESET);
for(i = 2; i < 48; i += 3) {
leds[i-1] = 200;
/*
leds[i-2] = 50;
leds[i-2] = 35;
*/
}
/* enable interrupts */
sei();
while (1) {
while (serial_available()) {
uint8_t c = serial_getchar();
if (c == '7')
serial_print("lol\n");
}
pwm();
}
}