A lampost demo program - it takes in SMS commands to control a light using the shiftbrite LED.
Dependencies: VodafoneUSBModem_bleedingedge mbed-rtos mbed
Fork of 3GShiftBrite by
Revision 1:662b59c2ce3a, committed 2012-11-19
- Comitter:
- nherriot
- Date:
- Mon Nov 19 17:34:14 2012 +0000
- Parent:
- 0:9a2bd692bc95
- Commit message:
- shiftbrite-lamp-post
Changed in this revision
VodafoneUSBModem_bleedingedge.lib | Show annotated file Show diff for this revision Revisions of this file |
main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 9a2bd692bc95 -r 662b59c2ce3a VodafoneUSBModem_bleedingedge.lib --- a/VodafoneUSBModem_bleedingedge.lib Fri Sep 28 09:27:18 2012 +0000 +++ b/VodafoneUSBModem_bleedingedge.lib Mon Nov 19 17:34:14 2012 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/donatien/code/VodafoneUSBModem_bleedingedge/#54ca82a7644c +http://mbed.org/users/donatien/code/VodafoneUSBModem_bleedingedge/#763eefc845b1
diff -r 9a2bd692bc95 -r 662b59c2ce3a main.cpp --- a/main.cpp Fri Sep 28 09:27:18 2012 +0000 +++ b/main.cpp Mon Nov 19 17:34:14 2012 +0000 @@ -35,6 +35,38 @@ latch=0; } +void doRainbow() { + for(int r=0; r<500; r++) { + for(int g=0; g<500; g++) { + for(int b=0; b<500; b++) { + setLEDColor(r,g,b); + } + } + } + setLEDColor(500,500,500); + Thread::wait(1000); + setLEDColor(0,0,0); +} + +void doFlash() { + int interval = 100; + for(int i=0; i<5; i++) { + setLEDColor(500,0,0); + Thread::wait(interval); + setLEDColor(0,0,0); + Thread::wait(interval); + setLEDColor(500,500,500); + Thread::wait(interval); + setLEDColor(0,0,0); + Thread::wait(interval); + setLEDColor(0,0,500); + Thread::wait(interval); + setLEDColor(0,0,0); + Thread::wait(interval); + } + setLEDColor(500,0,0); +} + void lightListener(void const*) { VodafoneUSBModem modem; @@ -47,7 +79,7 @@ int urlBufferLength = 128; // declare space for phone number and message storage - char numBuffer[20], msgBuffer[512]; + char numBuffer[20], msgBuffer[256]; size_t numSMS; // variable to track number of received messages //int ret = modem.connect("internet","web","web"); @@ -70,9 +102,61 @@ DBG("SM count > 0"); // get the oldest short message in the queue if(modem.getSM(numBuffer,msgBuffer,256)==OK) { - sscanf(msgBuffer,"%d,%d,%d",&r,&g,&b); + if(strcmp(msgBuffer,"flash")==0) { + doFlash(); + continue; + } else if(strcmp(msgBuffer,"rainbow")==0) { + doRainbow(); + continue; + } else if(strcmp(msgBuffer,"red")==0) { + setLEDColor(1000,0,0); + continue; + } else if(strcmp(msgBuffer,"green")==0) { + setLEDColor(0,1000,0); + continue; + } else if(strcmp(msgBuffer,"blue")==0) { + setLEDColor(0,0,1000); + continue; + } else if(strcmp(msgBuffer,"purple")==0) { + setLEDColor(1000,0,1000); + continue; + } else if(strcmp(msgBuffer,"off")==0) { + setLEDColor(0,0,0); + continue; + } + + if(sscanf(msgBuffer,"%d,%d,%d",&r,&g,&b)!=3) { + continue; + } DBG("Setting light to: %d,%d,%d",r,g,b); - setLEDColor(r*4,g*4,b*4); + + if(r<256) { + r *= 4; + } + + if(g<256) { + g *= 4; + } + + if(b<256) { + b *= 4; + } + + if(r>1023) { + r = 1023; + } + + if(g>1023) { + g = 1023; + } + + if(b>1023) { + b = 1023; + } + + setLEDColor(r,g,b); + + // connect to socket and push message /* // create the socket @@ -124,8 +208,8 @@ } - modem.disconnect(); - DBG("Disconnected"); + //modem.disconnect(); + //DBG("Disconnected"); while (1) { Thread::wait(100); @@ -137,7 +221,7 @@ led1 = !led1; Thread::wait(250); led1 = !led1; - Thread::wait(25000); + Thread::wait(750); } }