rsp to mbed
Dependencies: mbed neopixels_spi
Fork of RSP_receivefunction by
Diff: main.cpp
- Revision:
- 1:bcb384b83f54
- Parent:
- 0:3f93f42809e5
diff -r 3f93f42809e5 -r bcb384b83f54 main.cpp --- a/main.cpp Sat May 02 15:50:20 2015 +0000 +++ b/main.cpp Wed May 13 21:07:14 2015 +0000 @@ -1,5 +1,11 @@ #include "mbed.h" +#include "neopixels_spi.h" + +DigitalOut myled(LED1); +neopixels_spi lights; +Ticker xmas; + Serial pi(USBTX, USBRX);// Initialse USB serial port void mbedReceive(void); void modeActivated(void); @@ -14,19 +20,46 @@ void hunika(void); void akwansa(void); void rainbow(void); -void rgb(void); +void rgbm(void); void christmas2(void); void hunika2(void); void akwansa2(void); void rainbow2(void); -void rgb2(void); +void rgbm2(void); +//RSP packets dependencies int room=0; int mode=0; int red=0; int green=0; int blue=0; +//lights mode dependencies +int rg[8][3] = {{255,0,0},{0,255,0},{255,0,0},{0,255,0},{255,0,0},{0,255,0},{255,0,0},{0,225,0}}; +int gr[8][3] = {{0,255,0},{255,0,0},{0,255,0},{255,0,0},{0,255,0},{255,0,0},{0,225,0},{255,0,0}}; + +int bw[8][3] = {{0,0,255},{255,255,255},{0,0,255},{255,255,255},{0,0,255},{255,255,255},{0,0,255},{255,255,255}}; +int wb[8][3] = {{255,255,255},{0,0,255},{255,255,255},{0,0,255},{255,255,255},{0,0,255},{255,255,255},{0,0,255}}; + +int rgb[8][3] = {{255,0,0},{0,255,0},{0,0,255},{255,0,0},{0,255,0},{0,0,255},{255,0,0},{0,255,0}}; +int brg[8][3] = {{0,0,255},{255,0,0},{0,255,0},{0,0,255},{255,0,0},{0,255,0},{0,0,255},{255,0,0}}; +int gbr[8][3] = {{0,255,0},{0,0,255},{255,0,0},{0,255,0},{0,0,255},{255,0,0},{0,255,0},{0,0,255}}; +int bgr[8][3] = {{0,0,255},{0,255,0},{255,0,0},{0,0,255},{0,255,0},{255,0,0},{0,0,255},{0,255,0}}; + +int ak1[8][3] = {{255,0,0},{0,255,0},{0,0,0},{255,0,0},{0,255,0},{0,0,0},{255,0,0},{0,255,0}}; +int ak2[8][3] = {{0,0,0},{255,0,0},{0,255,0},{0,0,0},{255,0,0},{0,255,0},{0,0,0},{255,0,0}}; +int ak3[8][3] = {{0,255,0},{0,0,0},{255,0,0},{0,255,0},{0,0,0},{255,0,0},{0,255,0},{0,0,0}}; +int ak4[8][3] = {{0,0,0},{0,255,0},{255,0,0},{0,0,0},{0,255,0},{255,0,0},{0,0,0},{0,255,0}}; + +int ra1[8][3] = {{255,0,0},{255,165,0},{255,255,0},{255,255,255},{0,255,0},{0,0,255},{75,0,255},{238,130,238}}; +int ra2[8][3] = {{255,165,0},{255,255,0},{255,255,255},{0,255,0},{0,0,255},{75,0,255},{238,130,238},{255,0,0}}; +int ra3[8][3] = {{255,255,0},{255,255,255},{0,255,0},{0,0,255},{75,0,255},{238,130,238},{255,0,0},{255,165,0}}; +int ra4[8][3] = {{255,255,255},{0,255,0},{0,0,255},{75,0,255},{238,130,238},{255,0,0},{255,165,0},{255,255,0}}; +int ra5[8][3] = {{0,255,0},{0,0,255},{75,0,255},{238,130,238},{255,0,0},{255,165,0},{255,255,0},{255,255,255}}; +int ra6[8][3] = {{0,0,255},{75,0,255},{238,130,238},{255,0,0},{255,165,0},{255,255,0},{255,255,255},{0,255,0}}; +int ra7[8][3] = {{75,0,255},{238,130,238},{255,0,0},{255,165,0},{255,255,0},{255,255,255},{0,255,0},{0,0,255}}; +int ra8[8][3] = {{238,130,238},{255,0,0},{255,165,0},{255,255,0},{255,255,255},{0,255,0},{0,0,255},{75,0,255}}; + int main() { while(1) { @@ -52,6 +85,15 @@ } else if (section==0){ //normal lights function a way of stopping different light modes + // b2() stop alarm + room = pi.getc(); + if (room==1){ + //normal mode 1 + } + else if (room==2){ + //normal mode 2 + } + } } @@ -84,25 +126,25 @@ void brightness(void){ if (room==1){ - // setRGBStrip1(red, green, blue); + lights.setRGBStrip1(red, red, red); } if (room==2){ - // setRGBStrip2(red, green, blue); + lights.setRGBStrip2(red, red, red); } } void colour(void){ if (room==1){ - // setRGBStrip1(red, green, blue); + lights.setRGBStrip1(red, green, blue); } if (room==2){ - // setRGBStrip2(red, green, blue); + lights.setRGBStrip2(red, green, blue); } } void festive(void){ if (room==1){ if(red==1){ - christmas(); + christmas(); } if(red==2){ hunika(); @@ -114,11 +156,12 @@ rainbow(); } if(red==5){ - rgb(); + rgbm(); } } else if (room==2){ if(red==1){ + christmas2(); } if(red==2){ @@ -131,7 +174,7 @@ rainbow2(); } if(red==5){ - rgb2(); + rgbm2(); } } } @@ -150,33 +193,269 @@ } +//xmas red & green void christmas(void){ - + lights.setRGBPixels1(rg); + wait(1); + lights.setRGBPixels1(gr); + wait(1); + lights.setRGBPixels1(rg); + wait(1); + lights.setRGBPixels1(gr); + wait(1); + lights.setRGBPixels1(rg); + wait(1); + lights.setRGBPixels1(gr); + wait(1); + lights.setRGBPixels1(rg); + wait(1); + lights.setRGBPixels1(gr); + wait(1); + lights.setRGBPixels1(rg); + wait(1); + lights.setRGBPixels1(gr); + wait(1); + lights.setRGBStrip1(255, 0, 0); + wait(1); + lights.setRGBStrip1(0,255,0); + wait(1); } void hunika(void){ - + lights.setRGBPixels1(bw); + wait(1); + lights.setRGBPixels1(wb); + wait(1); + lights.setRGBPixels1(bw); + wait(1); + lights.setRGBPixels1(wb); + wait(1); + lights.setRGBPixels1(bw); + wait(1); + lights.setRGBPixels1(wb); + wait(1); + lights.setRGBPixels1(bw); + wait(1); + lights.setRGBPixels1(wb); + wait(1); + lights.setRGBPixels1(bw); + wait(1); + lights.setRGBPixels1(wb); + wait(1); + lights.setRGBStrip1(0, 0, 255); + wait(1); + lights.setRGBStrip1(255,255,255); + wait(1); } + void akwansa(void){ - + lights.setRGBPixels1(ak1); + wait(1); + lights.setRGBPixels1(ak2); + wait(1); + lights.setRGBPixels1(ak3); + wait(1); + lights.setRGBPixels1(ak4); + wait(1); + lights.setRGBPixels1(ak1); + wait(1); + lights.setRGBPixels1(ak2); + wait(1); + lights.setRGBPixels1(ak3); + wait(1); + lights.setRGBPixels1(ak4); + wait(1); + lights.setRGBPixels1(ak1); + wait(1); + lights.setRGBPixels1(ak2); + wait(1); + lights.setRGBPixels1(ak3); + wait(1); + lights.setRGBPixels1(ak4); + wait(1); } void rainbow(void){ - - } -void rgb(void){ - + lights.setRGBPixels1(ra1); + wait(1); + lights.setRGBPixels1(ra2); + wait(1); + lights.setRGBPixels1(ra3); + wait(1); + lights.setRGBPixels1(ra4); + wait(1); + lights.setRGBPixels1(ra5); + wait(1); + lights.setRGBPixels1(ra6); + wait(1); + lights.setRGBPixels1(ra7); + wait(1); + lights.setRGBPixels1(ra8); + wait(1); } -void christmas2(void){ +void rgbm(void){ + lights.setRGBPixels2(rgb); + wait(1); + lights.setRGBPixels2(brg); + wait(1); + lights.setRGBPixels2(gbr); + wait(1); + lights.setRGBPixels2(bgr); + wait(1); + lights.setRGBPixels2(rgb); + wait(1); + lights.setRGBPixels2(brg); + wait(1); + lights.setRGBPixels2(gbr); + wait(1); + lights.setRGBPixels2(bgr); + wait(1); + lights.setRGBPixels2(rgb); + wait(1); + lights.setRGBPixels2(brg); + wait(1); + lights.setRGBPixels2(gbr); + wait(1); + lights.setRGBPixels2(bgr); + wait(1); + lights.setRGBStrip2(255, 0, 0); + wait(1); + lights.setRGBStrip2(0,255,0); + wait(1); + lights.setRGBStrip2(0,0,255); + wait(1); } -void hunika2(void){ + +void christmas2(void){ + lights.setRGBPixels2(rg); + wait(1); + lights.setRGBPixels2(gr); + wait(1); + lights.setRGBPixels2(rg); + wait(1); + lights.setRGBPixels2(gr); + wait(1); + lights.setRGBPixels2(rg); + wait(1); + lights.setRGBPixels2(gr); + wait(1); + lights.setRGBPixels2(rg); + wait(1); + lights.setRGBPixels2(gr); + wait(1); + lights.setRGBPixels2(rg); + wait(1); + lights.setRGBPixels2(gr); + wait(1); + lights.setRGBStrip2(255, 0, 0); + wait(1); + lights.setRGBStrip2(0,255,0); + wait(1); + } +void hunika2(void){ + lights.setRGBPixels2(bw); + wait(1); + lights.setRGBPixels2(wb); + wait(1); + lights.setRGBPixels2(bw); + wait(1); + lights.setRGBPixels2(wb); + wait(1); + lights.setRGBPixels2(bw); + wait(1); + lights.setRGBPixels2(wb); + wait(1); + lights.setRGBPixels2(bw); + wait(1); + lights.setRGBPixels2(wb); + wait(1); + lights.setRGBPixels2(bw); + wait(1); + lights.setRGBPixels2(wb); + wait(1); + lights.setRGBStrip2(0, 0, 255); + wait(1); + lights.setRGBStrip2(255,255,255); + wait(1); } + void akwansa2(void){ + lights.setRGBPixels2(ak1); + wait(1); + lights.setRGBPixels2(ak2); + wait(1); + lights.setRGBPixels2(ak3); + wait(1); + lights.setRGBPixels2(ak4); + wait(1); + lights.setRGBPixels2(ak1); + wait(1); + lights.setRGBPixels2(ak2); + wait(1); + lights.setRGBPixels2(ak3); + wait(1); + lights.setRGBPixels2(ak4); + wait(1); + lights.setRGBPixels2(ak1); + wait(1); + lights.setRGBPixels2(ak2); + wait(1); + lights.setRGBPixels2(ak3); + wait(1); + lights.setRGBPixels2(ak4); + wait(1); + } - } + void rainbow2(void){ - + lights.setRGBPixels2(ra1); + wait(1); + lights.setRGBPixels2(ra2); + wait(1); + lights.setRGBPixels2(ra3); + wait(1); + lights.setRGBPixels2(ra4); + wait(1); + lights.setRGBPixels2(ra5); + wait(1); + lights.setRGBPixels2(ra6); + wait(1); + lights.setRGBPixels2(ra7); + wait(1); + lights.setRGBPixels2(ra8); + wait(1); } -void rgb2(void){ + +void rgbm2(void){ + lights.setRGBPixels2(rgb); + wait(1); + lights.setRGBPixels2(brg); + wait(1); + lights.setRGBPixels2(gbr); + wait(1); + lights.setRGBPixels2(bgr); + wait(1); + lights.setRGBPixels2(rgb); + wait(1); + lights.setRGBPixels2(brg); + wait(1); + lights.setRGBPixels2(gbr); + wait(1); + lights.setRGBPixels2(bgr); + wait(1); + lights.setRGBPixels2(rgb); + wait(1); + lights.setRGBPixels2(brg); + wait(1); + lights.setRGBPixels2(gbr); + wait(1); + lights.setRGBPixels2(bgr); + wait(1); + lights.setRGBStrip2(255, 0, 0); + wait(1); + lights.setRGBStrip2(0,255,0); + wait(1); + lights.setRGBStrip2(0,0,255); + wait(1); } \ No newline at end of file