A simple example to drive an APA-102 LED strip.
Dependencies: mbed APA102b Ping SLCD
Diff: main.cpp
- Revision:
- 3:2788a714b18e
- Parent:
- 2:5a9388a7ac62
- Child:
- 4:50ce957663ee
--- a/main.cpp Mon Apr 06 13:57:50 2015 +0000 +++ b/main.cpp Tue Apr 07 13:55:22 2015 +0000 @@ -1,8 +1,11 @@ #include "mbed.h" #include "Ping.h" +#include "SLCD.h" + #include "APA102a.h" -//SPI spi(PTA16, PTA17, PTA15); // mosi, miso, sclk +SLCD slcd; +DigitalIn Button(PTC12); Ping ping(PTA13); APA102a LEDs(PTA16, PTA17, PTA15,1000000); // mosi, miso, sclk, rate @@ -66,12 +69,14 @@ int rgb[3]; unsigned char r,g,b; - const int N=67; // Number of APA-102 Elements +1 + //const int N=67; // Number of APA-102 Elements +1 + const int N=144; int range; unsigned int Pixel; unsigned int Pixels[N]; float hue,sat,ints; + float hue_adjust =0; const int NumberOfRays = 19; @@ -116,12 +121,39 @@ int colors=0x000000; + + int Mode=0; + const int NModes = 4; + LEDs.SetBuffer(Pixels,1,N, N,0, false,false); - + slcd.Home(); + slcd.printf("%d",Mode); + while (true) { ping.Send(); wait_ms(50); // update rate. range = ping.Read_cm(); + colors+=range/10; + + if (!Button ){ + Mode++; + Mode = (Mode %NModes); + slcd.Home(); + slcd.printf("%d",Mode); + + } + + switch(Mode){ + case 0: hue_adjust =0; + break; // just display the last "static" image + case 1: hue_adjust = range; // rotate the hue by the range + break; + case 2: hue_adjust = colors; // change the spin rate by the range + break; + case 3: hue_adjust++; // spin at a fixed rate + break; + + } for(int i=0;i<NumberOfRays;i++) @@ -130,7 +162,7 @@ { for(int k=0;k<j;k++) { - hue = RayHues[i]; + hue = RayHues[i]+ hue_adjust; sat = RaySats[i]; ints = RayInts[i]; hsi2rgb(hue, sat, ints,rgb); @@ -143,7 +175,22 @@ } } } + /* + for(int i=0;i<N;i++) + { + hue = (1.0*i)/(1.0*N) * 360 + hue_adjust; + sat = 0.8; + ints = 0.7; + hsi2rgb(hue, sat, ints,rgb); + r = rgb[0]; + g = rgb[1]; + b = rgb[2]; + + Pixel=LEDs.IRGB(7,r,g,b); + Pixels[i]=Pixel; + } + */ LEDs.Repaint(); - colors+=range/10; + } } \ No newline at end of file