Example code for driving the WS2801 LEDs

Dependencies:   mbed

Committer:
bridadan
Date:
Thu May 28 14:28:24 2015 +0000
Revision:
0:4d2472ee7b7c
Initial Commit

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bridadan 0:4d2472ee7b7c 1 #include "mbed.h"
bridadan 0:4d2472ee7b7c 2
bridadan 0:4d2472ee7b7c 3 #define LED_COUNT 22
bridadan 0:4d2472ee7b7c 4 DigitalOut gpo(D0);
bridadan 0:4d2472ee7b7c 5 DigitalOut led(LED_RED);
bridadan 0:4d2472ee7b7c 6 SPI spi(D11, D12, D13);
bridadan 0:4d2472ee7b7c 7
bridadan 0:4d2472ee7b7c 8
bridadan 0:4d2472ee7b7c 9 void writeCol(int r, int g, int b) {
bridadan 0:4d2472ee7b7c 10 for (int i = 0; i < LED_COUNT; i++) {
bridadan 0:4d2472ee7b7c 11 spi.write(r);
bridadan 0:4d2472ee7b7c 12 spi.write(g);
bridadan 0:4d2472ee7b7c 13 spi.write(b);
bridadan 0:4d2472ee7b7c 14 }
bridadan 0:4d2472ee7b7c 15 }
bridadan 0:4d2472ee7b7c 16
bridadan 0:4d2472ee7b7c 17 int main()
bridadan 0:4d2472ee7b7c 18 {
bridadan 0:4d2472ee7b7c 19 int r = 0;
bridadan 0:4d2472ee7b7c 20
bridadan 0:4d2472ee7b7c 21 while(true) {
bridadan 0:4d2472ee7b7c 22
bridadan 0:4d2472ee7b7c 23 for (int i = 0; i <= 0xFF; i++) {
bridadan 0:4d2472ee7b7c 24 writeCol(i, 0, 0);
bridadan 0:4d2472ee7b7c 25 wait(0.01);
bridadan 0:4d2472ee7b7c 26 }
bridadan 0:4d2472ee7b7c 27
bridadan 0:4d2472ee7b7c 28 for (int i = 0xFF; i >= 0x00; i--) {
bridadan 0:4d2472ee7b7c 29 writeCol(i, 0, 0);
bridadan 0:4d2472ee7b7c 30 wait(0.01);
bridadan 0:4d2472ee7b7c 31 }
bridadan 0:4d2472ee7b7c 32 }
bridadan 0:4d2472ee7b7c 33 }