44 lines
544 B
C
44 lines
544 B
C
#include "WS2812B_Atmega.h"
|
|
|
|
inline void writeZero() {
|
|
DATAPIN = 1;
|
|
wait6;
|
|
DATAPIN = 0;
|
|
wait15;
|
|
}
|
|
|
|
inline void writeOne() {
|
|
DATAPIN = 1;
|
|
wait14;
|
|
DATAPIN = 0;
|
|
wait8;
|
|
}
|
|
|
|
void writeRGB(uint8_t r, uint8_t g, uint8_t b) {
|
|
int i;
|
|
|
|
for( i = 128; i > 0; i >>= 1 ) {
|
|
if( g & i ){
|
|
writeOne();
|
|
} else {
|
|
writeZero();
|
|
}
|
|
}
|
|
|
|
for( i = 128; i > 0; i >>= 1 ) {
|
|
if( r & i ){
|
|
writeOne();
|
|
} else {
|
|
writeZero();
|
|
}
|
|
}
|
|
|
|
for( i = 128; i > 0; i >>= 1 ) {
|
|
if( b & i ){
|
|
writeOne();
|
|
} else {
|
|
writeZero();
|
|
}
|
|
}
|
|
}
|