Spidey Wall is the name for a physical wall lit up by multiple addressable LED strips. This program is an LPC1768 web server to control the wall from a browser.

Dependencies:   EthernetInterfacePlusHostname RdWebServer mbed-rtos mbed

This project is part of a Light-Wall using addressable LED strips (WS2801). I have published a few posts on my blog about the construction of the wall and building a game to play on it (PacMan). I have also had a guest post from a friend who has set his children the task of producing some interesting animations. The original post is http://robdobson.com/2015/07/spidey-wall/ /media/uploads/Bobty/20130722_112945_img_9674_62895-1184x1579.jpg

So far, however, I hadn't fully connected the physical (and electronic) wall with the web-browser creations to drive it. This project is hopefully the final link. A fast and reliable web server using REST commands to drive the 1686 LEDs in the Spidey Wall from code running in a browser (say on an iPad while you are playing a game).

The approach taken here results in the ability to control the RGB values of all 1686 LEDs at a rate of 20 frames per second.

A blog post describing the whole thing is here:

http://robdobson.com/2015/08/a-reliable-mbed-webserver/

Committer:
Bobty
Date:
Tue Aug 18 16:03:29 2015 +0000
Revision:
0:887096209439
Child:
1:362331cec9b7
Initial - unchanged since 2013

Who changed what in which revision?

UserRevisionLine numberNew contents of line
Bobty 0:887096209439 1 /* main.cpp
Bobty 0:887096209439 2 Rob Dobson 2013
Bobty 0:887096209439 3 More details at ???
Bobty 0:887096209439 4 */
Bobty 0:887096209439 5
Bobty 0:887096209439 6 #include "mbed.h"
Bobty 0:887096209439 7 #include "EthernetInterface.h"
Bobty 0:887096209439 8 #include <stdio.h>
Bobty 0:887096209439 9 #include <string.h>
Bobty 0:887096209439 10 #include "RdWebServer.h"
Bobty 0:887096209439 11 #include "ledstrip.h"
Bobty 0:887096209439 12 #include "LedCmdHandler.h"
Bobty 0:887096209439 13
Bobty 0:887096209439 14 #define PORT 80
Bobty 0:887096209439 15
Bobty 0:887096209439 16 Serial pc(USBTX, USBRX);
Bobty 0:887096209439 17
Bobty 0:887096209439 18 RdWebServer webServer;
Bobty 0:887096209439 19
Bobty 0:887096209439 20 EthernetInterface eth;
Bobty 0:887096209439 21
Bobty 0:887096209439 22 DigitalOut led1(LED1); //server listning status
Bobty 0:887096209439 23 DigitalOut led2(LED2); //socket connecting status
Bobty 0:887096209439 24
Bobty 0:887096209439 25 Ticker ledTick;
Bobty 0:887096209439 26
Bobty 0:887096209439 27 char nameOfLights[50];
Bobty 0:887096209439 28 int ledsCount = 904;
Bobty 0:887096209439 29 int ledSplitPoint = 448;
Bobty 0:887096209439 30 ledstrip* pLedStrip = NULL;
Bobty 0:887096209439 31
Bobty 0:887096209439 32 char* indexHtmName = "index.htm";
Bobty 0:887096209439 33
Bobty 0:887096209439 34 const int TICK_MS = 100;
Bobty 0:887096209439 35 LedCmdHandler* pLedCmdHandler = NULL;
Bobty 0:887096209439 36 int blinkCtr = 0;
Bobty 0:887096209439 37
Bobty 0:887096209439 38 void ledTickfunc()
Bobty 0:887096209439 39 {
Bobty 0:887096209439 40 if(webServer.isListening())
Bobty 0:887096209439 41 {
Bobty 0:887096209439 42 blinkCtr++;
Bobty 0:887096209439 43 if (blinkCtr > 1)
Bobty 0:887096209439 44 {
Bobty 0:887096209439 45 led1 = !led1;
Bobty 0:887096209439 46 blinkCtr = 0;
Bobty 0:887096209439 47 }
Bobty 0:887096209439 48 }
Bobty 0:887096209439 49 else
Bobty 0:887096209439 50 {
Bobty 0:887096209439 51 led1 = false;
Bobty 0:887096209439 52 }
Bobty 0:887096209439 53
Bobty 0:887096209439 54 if (pLedCmdHandler != NULL)
Bobty 0:887096209439 55 pLedCmdHandler->NextGen();
Bobty 0:887096209439 56 }
Bobty 0:887096209439 57
Bobty 0:887096209439 58 void handleCmd_ledControl(char* cmdStr, char* argStr)
Bobty 0:887096209439 59 {
Bobty 0:887096209439 60 printf("LEDS COMMAND %s %s\r\n", cmdStr, argStr);
Bobty 0:887096209439 61 if (argStr == NULL)
Bobty 0:887096209439 62 return;
Bobty 0:887096209439 63 pLedCmdHandler->DoCommand(argStr);
Bobty 0:887096209439 64
Bobty 0:887096209439 65 // Store last command
Bobty 0:887096209439 66 LocalFileSystem local("local");
Bobty 0:887096209439 67 FILE* fp = fopen("/local/lastcmd.inf", "w");
Bobty 0:887096209439 68 if (fp != NULL)
Bobty 0:887096209439 69 {
Bobty 0:887096209439 70 fwrite(argStr, 1, strlen(argStr)+1, fp);
Bobty 0:887096209439 71 fclose(fp);
Bobty 0:887096209439 72 }
Bobty 0:887096209439 73 }
Bobty 0:887096209439 74
Bobty 0:887096209439 75 void reRunLastCommand()
Bobty 0:887096209439 76 {
Bobty 0:887096209439 77 // Store last command
Bobty 0:887096209439 78 LocalFileSystem local("local");
Bobty 0:887096209439 79 FILE* fp = fopen("/local/lastcmd.inf", "r");
Bobty 0:887096209439 80 if (fp != NULL)
Bobty 0:887096209439 81 {
Bobty 0:887096209439 82 char buf[501];
Bobty 0:887096209439 83 buf[sizeof(buf)-1] = 0;
Bobty 0:887096209439 84 int nread = fread(buf, 1, sizeof(buf), fp);
Bobty 0:887096209439 85 fclose(fp);
Bobty 0:887096209439 86 if (nread > 0 && nread <= sizeof(buf))
Bobty 0:887096209439 87 {
Bobty 0:887096209439 88 buf[nread] = 0;
Bobty 0:887096209439 89 pLedCmdHandler->DoCommand(buf);
Bobty 0:887096209439 90 }
Bobty 0:887096209439 91 }
Bobty 0:887096209439 92 }
Bobty 0:887096209439 93
Bobty 0:887096209439 94 #include "colourconverters.h"
Bobty 0:887096209439 95
Bobty 0:887096209439 96 void BodgeSmooth(ledstrip* pLedStrip)
Bobty 0:887096209439 97 {
Bobty 0:887096209439 98 pLedStrip->Clear();
Bobty 0:887096209439 99 pLedStrip->ShowLeds();
Bobty 0:887096209439 100
Bobty 0:887096209439 101
Bobty 0:887096209439 102 RgbColor startRGB(50,0,0);
Bobty 0:887096209439 103 HsvColor curHsv = RgbToHsv(startRGB);
Bobty 0:887096209439 104 while(1)
Bobty 0:887096209439 105 for (int k = 0; k < 1000; k++)
Bobty 0:887096209439 106 for (int j = 0; j < 255; j++)
Bobty 0:887096209439 107 {
Bobty 0:887096209439 108 pLedStrip->Clear();
Bobty 0:887096209439 109 RgbColor colrVal = HsvToRgb(curHsv);
Bobty 0:887096209439 110 pLedStrip->Fill(0,pLedStrip->GetNumLeds(),colrVal.r, colrVal.g, colrVal.b);
Bobty 0:887096209439 111 pLedStrip->ShowLeds();
Bobty 0:887096209439 112 wait_ms(250);
Bobty 0:887096209439 113 curHsv.h++;
Bobty 0:887096209439 114 }
Bobty 0:887096209439 115 }
Bobty 0:887096209439 116
Bobty 0:887096209439 117 void setLightsConfig()
Bobty 0:887096209439 118 {
Bobty 0:887096209439 119 printf("Rob LightWall - Configured for ");
Bobty 0:887096209439 120 // Check for a config file on the local file system
Bobty 0:887096209439 121 strcpy(nameOfLights, "Spidey");
Bobty 0:887096209439 122 LocalFileSystem local("local");
Bobty 0:887096209439 123 FILE* fp = fopen("/local/spidey.cnf", "r");
Bobty 0:887096209439 124 if (fp != NULL)
Bobty 0:887096209439 125 {
Bobty 0:887096209439 126 char buf[201];
Bobty 0:887096209439 127 buf[sizeof(buf)-1] = 0;
Bobty 0:887096209439 128 int nread = fread(buf, 1, sizeof(buf), fp);
Bobty 0:887096209439 129 if (nread > 0 && nread <= sizeof(buf))
Bobty 0:887096209439 130 {
Bobty 0:887096209439 131 buf[nread] = 0;
Bobty 0:887096209439 132 sscanf(buf, "%s %d %d", nameOfLights, &ledsCount, &ledSplitPoint);
Bobty 0:887096209439 133 }
Bobty 0:887096209439 134 fclose(fp);
Bobty 0:887096209439 135 printf("%s (%d LEDs, Split at %d)", nameOfLights, ledsCount, ledSplitPoint);
Bobty 0:887096209439 136 printf("\n\r");
Bobty 0:887096209439 137 }
Bobty 0:887096209439 138
Bobty 0:887096209439 139 // Leds setup
Bobty 0:887096209439 140 pLedStrip = new ledstrip(ledsCount, ledSplitPoint);
Bobty 0:887096209439 141 wait_ms(100);
Bobty 0:887096209439 142 pLedStrip->Clear();
Bobty 0:887096209439 143 pLedStrip->ShowLeds();
Bobty 0:887096209439 144
Bobty 0:887096209439 145 // Cmd handler
Bobty 0:887096209439 146 pLedCmdHandler = new LedCmdHandler(pLedStrip);
Bobty 0:887096209439 147 }
Bobty 0:887096209439 148
Bobty 0:887096209439 149 int main (void)
Bobty 0:887096209439 150 {
Bobty 0:887096209439 151 pc.baud(115200);
Bobty 0:887096209439 152
Bobty 0:887096209439 153 setLightsConfig();
Bobty 0:887096209439 154
Bobty 0:887096209439 155 BodgeSmooth(pLedStrip);
Bobty 0:887096209439 156
Bobty 0:887096209439 157 ledTick.attach(&ledTickfunc,TICK_MS / 1000.0);
Bobty 0:887096209439 158
Bobty 0:887096209439 159 // reRunLastCommand();
Bobty 0:887096209439 160
Bobty 0:887096209439 161 // setup ethernet interface
Bobty 0:887096209439 162 eth.init(); //Use DHCP
Bobty 0:887096209439 163 eth.connect();
Bobty 0:887096209439 164 printf("IP Address is %s\n\r", eth.getIPAddress());
Bobty 0:887096209439 165
Bobty 0:887096209439 166 webServer.addCommand("", RdWebServerCmdDef::CMD_LOCALFILE, NULL, indexHtmName, true);
Bobty 0:887096209439 167 webServer.addCommand("cmd", RdWebServerCmdDef::CMD_CALLBACK, &handleCmd_ledControl);
Bobty 0:887096209439 168 webServer.init(PORT, &led2);
Bobty 0:887096209439 169 webServer.run();
Bobty 0:887096209439 170 }