Testing WS2801

Dependencies:   mbed

Fork of ws2801 by Thomas Olsson

Committer:
lab4d
Date:
Mon May 26 20:05:07 2014 +0000
Revision:
8:22469b6544d2
Compiling version, still not working :/

Who changed what in which revision?

UserRevisionLine numberNew contents of line
lab4d 8:22469b6544d2 1 #include "mbed.h"
lab4d 8:22469b6544d2 2 #include "ws2801.h"
lab4d 8:22469b6544d2 3
lab4d 8:22469b6544d2 4 #define STRIP_LENGTH 40
lab4d 8:22469b6544d2 5
lab4d 8:22469b6544d2 6 ws2801 mystrip(p9, p10, STRIP_LENGTH);
lab4d 8:22469b6544d2 7
lab4d 8:22469b6544d2 8 int dir=1, level=10;
lab4d 8:22469b6544d2 9 int rainbow[] = {0xff00ff,0xff00cc,0xff0099,0xff0066,0xff0033,0xff0000,0xff3300,0xff6600,
lab4d 8:22469b6544d2 10 0xff9900,0xffcc00,0xffff00,0xccff00,0x99ff00,0x66ff00,0x33ff00,0x00ff00,
lab4d 8:22469b6544d2 11 0x00ff33,0x00ff66,0x00ff99,0x00ffcc,0x00ffff,0x00ccff,0x0099ff,0x0066ff,
lab4d 8:22469b6544d2 12 0x0033ff,0x0000ff,0x3300ff,0x6600ff,0x9900ff,0xcc00ff,0x9900ff,0x6600ff
lab4d 8:22469b6544d2 13 };
lab4d 8:22469b6544d2 14
lab4d 8:22469b6544d2 15 void move(void){
lab4d 8:22469b6544d2 16 int temp = rainbow[31];
lab4d 8:22469b6544d2 17 for (int x = (STRIP_LENGTH - 1) ; x > 0 ; x--) rainbow[x] = rainbow[x - 1];
lab4d 8:22469b6544d2 18 rainbow[0] = temp;
lab4d 8:22469b6544d2 19 }
lab4d 8:22469b6544d2 20
lab4d 8:22469b6544d2 21 void pulse(void){
lab4d 8:22469b6544d2 22 if(dir)
lab4d 8:22469b6544d2 23 {
lab4d 8:22469b6544d2 24 mystrip.level(level+=2);
lab4d 8:22469b6544d2 25 if(level >= 100)dir = 0;
lab4d 8:22469b6544d2 26 }
lab4d 8:22469b6544d2 27 else if(!dir)
lab4d 8:22469b6544d2 28 {
lab4d 8:22469b6544d2 29 mystrip.level(level--);
lab4d 8:22469b6544d2 30 if(level <= 5)dir = 1;
lab4d 8:22469b6544d2 31 }
lab4d 8:22469b6544d2 32 }
lab4d 8:22469b6544d2 33
lab4d 8:22469b6544d2 34 int main() {
lab4d 8:22469b6544d2 35 mystrip.level(level);
lab4d 8:22469b6544d2 36 while(1)
lab4d 8:22469b6544d2 37 {
lab4d 8:22469b6544d2 38 move();
lab4d 8:22469b6544d2 39 pulse();
lab4d 8:22469b6544d2 40 mystrip.post(rainbow);
lab4d 8:22469b6544d2 41 wait_ms(100);
lab4d 8:22469b6544d2 42 }
lab4d 8:22469b6544d2 43 }