Simple test for commanding the RGB LED. Use your mbed websocket to send a message, composed by a letter and a number. The letter can be 'r', 'g', or 'b', which is the LED color, and the number is 0 or 1, which is the logic state. Remember that the board LEDs light up with a 0 level.
Dependencies: WebSocketClient mbed-rtos mbed
Diff: main.cpp
- Revision:
- 0:35bd27c75bc9
- Child:
- 1:ba6266c183de
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Thu Aug 07 17:48:14 2014 +0000 @@ -0,0 +1,62 @@ +#include "mbed.h" +#include "EthernetInterface.h" +#include "Websocket.h" + +DigitalOut ledr(PTB22); +DigitalOut ledg(PTE26); +DigitalOut ledb(PTB21); +DigitalIn sw(PTA4); + +int main() { + int res; + char buf[100]; + char msg[100]; + ledg = 1; + ledr = 1; + ledb = 1; + bool pb = 1; + + printf("START\r\n"); + EthernetInterface eth; + eth.init(); + eth.connect(); + printf("IP Address is %s\n\r", eth.getIPAddress()); + wait(1.0); + + Websocket ws("ws://sockets.mbed.org/ws/quevedo/ro"); + ws.connect(); + + while (pb) { + if(!ws.read(buf)) { + if(buf[0] == 'r') { + if(buf[1] == '0') { + ledr = 0; + } else { + ledr = 1; + } + } + if(buf[0] == 'g') { + if(buf[1] == '0') { + ledg = 0; + } else { + ledg = 1; + } + } + if(buf[0] == 'b') { + if(buf[1] == '0') { + ledb = 0; + } else { + ledb = 1; + } + } + } + pb = sw; + } + ws.close(); + eth.disconnect(); + ledg = 1; + ledr = 1; + ledb = 1; + while(1) { + } +}