nima aghli
/
WS2811
for thww WS2811 RGB
Fork of WS2811 by
WS2811.cpp@4:46b52a6a943b, 2016-11-23 (annotated)
- Committer:
- nimaaghli
- Date:
- Wed Nov 23 19:41:34 2016 +0000
- Revision:
- 4:46b52a6a943b
- Parent:
- 3:2fbb2f0e79fb
first commit
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Drohne | 0:c6a6fa47dadc | 1 | /* |
Drohne | 0:c6a6fa47dadc | 2 | * Creator: Matthias Hemmer |
Drohne | 0:c6a6fa47dadc | 3 | * created: 15.04.2016 |
Drohne | 0:c6a6fa47dadc | 4 | * |
Drohne | 0:c6a6fa47dadc | 5 | * function: write a register of 8 bits to the WS2811 RGBs |
Drohne | 0:c6a6fa47dadc | 6 | */ |
Drohne | 0:c6a6fa47dadc | 7 | #include "mbed.h" |
Drohne | 0:c6a6fa47dadc | 8 | #include "WS2811.h" |
Drohne | 0:c6a6fa47dadc | 9 | |
Drohne | 2:ccf3f0c36dae | 10 | uint8_t ledmatrix[LED_MAX][3]; |
Drohne | 0:c6a6fa47dadc | 11 | |
nimaaghli | 4:46b52a6a943b | 12 | DigitalOut myled(PB_5); |
Drohne | 0:c6a6fa47dadc | 13 | |
Drohne | 0:c6a6fa47dadc | 14 | void writeled(int pos, uint8_t g, uint8_t r, uint8_t b){ // define the register |
Drohne | 0:c6a6fa47dadc | 15 | ledmatrix[pos][0] = g; // green register |
Drohne | 0:c6a6fa47dadc | 16 | ledmatrix[pos][1] = r; // red register |
Drohne | 0:c6a6fa47dadc | 17 | ledmatrix[pos][2] = b; // blue register |
Drohne | 0:c6a6fa47dadc | 18 | } |
Drohne | 0:c6a6fa47dadc | 19 | |
Drohne | 0:c6a6fa47dadc | 20 | void writeledbit(char wert){ |
Drohne | 0:c6a6fa47dadc | 21 | |
Drohne | 0:c6a6fa47dadc | 22 | if(wert){ // example: if(1) than make what is declatrated |
Drohne | 0:c6a6fa47dadc | 23 | myled = 1; |
Drohne | 0:c6a6fa47dadc | 24 | for(int i=0;i<HIGH_SIGNAL;i++) __nop(); // wait is to slow, becouse reset = 50µs |
Drohne | 0:c6a6fa47dadc | 25 | myled = 0; |
Drohne | 0:c6a6fa47dadc | 26 | for(int i=0;i<LOW_SIGNAL;i++) __nop(); |
Drohne | 0:c6a6fa47dadc | 27 | } |
Drohne | 0:c6a6fa47dadc | 28 | |
Drohne | 0:c6a6fa47dadc | 29 | else{ // else make this |
Drohne | 0:c6a6fa47dadc | 30 | myled = 1; |
Drohne | 0:c6a6fa47dadc | 31 | for(int i=0;i<LOW_SIGNAL;i++) __nop(); |
Drohne | 0:c6a6fa47dadc | 32 | myled = 0; |
Drohne | 0:c6a6fa47dadc | 33 | for(int i=0;i<HIGH_SIGNAL;i++) __nop(); |
Drohne | 0:c6a6fa47dadc | 34 | } |
Drohne | 0:c6a6fa47dadc | 35 | } |
Drohne | 0:c6a6fa47dadc | 36 | |
Drohne | 0:c6a6fa47dadc | 37 | void sendColours(int pos, uint8_t r, uint8_t g, uint8_t b){ |
Drohne | 3:2fbb2f0e79fb | 38 | //__disable_irq; // disable interrupt to speed up |
Drohne | 0:c6a6fa47dadc | 39 | writeled(pos, g, r, b); // call the underprogramm |
Drohne | 0:c6a6fa47dadc | 40 | |
Drohne | 0:c6a6fa47dadc | 41 | for(int led = 0; led < LED_MAX; led++){ // write the matrix on the RGBs |
Drohne | 0:c6a6fa47dadc | 42 | for(int i = 0; i < 3; i++){ // write the position |
Drohne | 0:c6a6fa47dadc | 43 | for(int b = 0; b < 8; b++){ // write the bit |
Drohne | 0:c6a6fa47dadc | 44 | writeledbit(ledmatrix[led][i] & 1<<b); // write the byte on the RGBs |
Drohne | 0:c6a6fa47dadc | 45 | } |
Drohne | 0:c6a6fa47dadc | 46 | } |
Drohne | 0:c6a6fa47dadc | 47 | } |
Drohne | 0:c6a6fa47dadc | 48 | wait(DELAY); // wait for the supply voltage |
Drohne | 3:2fbb2f0e79fb | 49 | // __enable_irq; // enable interrupt pin for the basic uses |
Drohne | 0:c6a6fa47dadc | 50 | } |