-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathws2803.c
57 lines (46 loc) · 1.01 KB
/
ws2803.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
/*
* ws2803.c
*
* Created: 05.05.2013 16:46:25
* Author: Christoph
*/
#include "ws2803.h"
void ws2803_setPixel(uint8_t r, uint8_t g, uint8_t b) {
uint8_t color;
color =r;
for(int8_t digit =7;digit >=0;digit--) {
WS2803_PORT &=~(1<<CKI_PIN);
if(color & (1<<digit))
WS2803_PORT |=(1<<SDI_PIN);
else
WS2803_PORT &=~(1<<SDI_PIN);
WS2803_PORT |=(1<<CKI_PIN);
}
color =g;
for(int8_t digit =7;digit >=0;digit--) {
WS2803_PORT &=~(1<<CKI_PIN);
if(color & (1<<digit))
WS2803_PORT |=(1<<SDI_PIN);
else
WS2803_PORT &=~(1<<SDI_PIN);
WS2803_PORT |=(1<<CKI_PIN);
}
color =b;
for(int8_t digit =7;digit >=0;digit--) {
WS2803_PORT &=~(1<<CKI_PIN);
if(color & (1<<digit))
WS2803_PORT |=(1<<SDI_PIN);
else
WS2803_PORT &=~(1<<SDI_PIN);
WS2803_PORT |=(1<<CKI_PIN);
}
}
void ws2803_show() {
WS2803_PORT |=(1<<CKI_PIN);
WS2803_PORT &=~(1<<CKI_PIN);
_delay_us(500);
}
void ws2803_init() {
WS2803_DDR |=(1<<CKI_PIN) | (1<<SDI_PIN);
ws2803_show();
}