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/
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/
colourconverters.cpp@0:887096209439, 2015-08-18 (annotated)
- Committer:
- Bobty
- Date:
- Tue Aug 18 16:03:29 2015 +0000
- Revision:
- 0:887096209439
- Child:
- 6:8df79fe1afcd
Initial - unchanged since 2013
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Bobty | 0:887096209439 | 1 | #include "colourconverters.h" |
Bobty | 0:887096209439 | 2 | |
Bobty | 0:887096209439 | 3 | RgbColor HsvToRgb(HsvColor hsv) |
Bobty | 0:887096209439 | 4 | { |
Bobty | 0:887096209439 | 5 | RgbColor rgb(0,0,0); |
Bobty | 0:887096209439 | 6 | unsigned char region, remainder, p, q, t; |
Bobty | 0:887096209439 | 7 | |
Bobty | 0:887096209439 | 8 | if (hsv.s == 0) |
Bobty | 0:887096209439 | 9 | { |
Bobty | 0:887096209439 | 10 | rgb.r = hsv.v; |
Bobty | 0:887096209439 | 11 | rgb.g = hsv.v; |
Bobty | 0:887096209439 | 12 | rgb.b = hsv.v; |
Bobty | 0:887096209439 | 13 | return rgb; |
Bobty | 0:887096209439 | 14 | } |
Bobty | 0:887096209439 | 15 | |
Bobty | 0:887096209439 | 16 | region = hsv.h / 43; |
Bobty | 0:887096209439 | 17 | remainder = (hsv.h - (region * 43)) * 6; |
Bobty | 0:887096209439 | 18 | |
Bobty | 0:887096209439 | 19 | p = (hsv.v * (255 - hsv.s)) >> 8; |
Bobty | 0:887096209439 | 20 | q = (hsv.v * (255 - ((hsv.s * remainder) >> 8))) >> 8; |
Bobty | 0:887096209439 | 21 | t = (hsv.v * (255 - ((hsv.s * (255 - remainder)) >> 8))) >> 8; |
Bobty | 0:887096209439 | 22 | |
Bobty | 0:887096209439 | 23 | switch (region) |
Bobty | 0:887096209439 | 24 | { |
Bobty | 0:887096209439 | 25 | case 0: |
Bobty | 0:887096209439 | 26 | rgb.r = hsv.v; rgb.g = t; rgb.b = p; |
Bobty | 0:887096209439 | 27 | break; |
Bobty | 0:887096209439 | 28 | case 1: |
Bobty | 0:887096209439 | 29 | rgb.r = q; rgb.g = hsv.v; rgb.b = p; |
Bobty | 0:887096209439 | 30 | break; |
Bobty | 0:887096209439 | 31 | case 2: |
Bobty | 0:887096209439 | 32 | rgb.r = p; rgb.g = hsv.v; rgb.b = t; |
Bobty | 0:887096209439 | 33 | break; |
Bobty | 0:887096209439 | 34 | case 3: |
Bobty | 0:887096209439 | 35 | rgb.r = p; rgb.g = q; rgb.b = hsv.v; |
Bobty | 0:887096209439 | 36 | break; |
Bobty | 0:887096209439 | 37 | case 4: |
Bobty | 0:887096209439 | 38 | rgb.r = t; rgb.g = p; rgb.b = hsv.v; |
Bobty | 0:887096209439 | 39 | break; |
Bobty | 0:887096209439 | 40 | default: |
Bobty | 0:887096209439 | 41 | rgb.r = hsv.v; rgb.g = p; rgb.b = q; |
Bobty | 0:887096209439 | 42 | break; |
Bobty | 0:887096209439 | 43 | } |
Bobty | 0:887096209439 | 44 | |
Bobty | 0:887096209439 | 45 | return rgb; |
Bobty | 0:887096209439 | 46 | } |
Bobty | 0:887096209439 | 47 | |
Bobty | 0:887096209439 | 48 | HsvColor RgbToHsv(RgbColor rgb) |
Bobty | 0:887096209439 | 49 | { |
Bobty | 0:887096209439 | 50 | HsvColor hsv(0,0,0); |
Bobty | 0:887096209439 | 51 | unsigned char rgbMin, rgbMax; |
Bobty | 0:887096209439 | 52 | |
Bobty | 0:887096209439 | 53 | rgbMin = rgb.r < rgb.g ? (rgb.r < rgb.b ? rgb.r : rgb.b) : (rgb.g < rgb.b ? rgb.g : rgb.b); |
Bobty | 0:887096209439 | 54 | rgbMax = rgb.r > rgb.g ? (rgb.r > rgb.b ? rgb.r : rgb.b) : (rgb.g > rgb.b ? rgb.g : rgb.b); |
Bobty | 0:887096209439 | 55 | |
Bobty | 0:887096209439 | 56 | hsv.v = rgbMax; |
Bobty | 0:887096209439 | 57 | if (hsv.v == 0) |
Bobty | 0:887096209439 | 58 | { |
Bobty | 0:887096209439 | 59 | hsv.h = 0; |
Bobty | 0:887096209439 | 60 | hsv.s = 0; |
Bobty | 0:887096209439 | 61 | return hsv; |
Bobty | 0:887096209439 | 62 | } |
Bobty | 0:887096209439 | 63 | |
Bobty | 0:887096209439 | 64 | hsv.s = 255 * long(rgbMax - rgbMin) / hsv.v; |
Bobty | 0:887096209439 | 65 | if (hsv.s == 0) |
Bobty | 0:887096209439 | 66 | { |
Bobty | 0:887096209439 | 67 | hsv.h = 0; |
Bobty | 0:887096209439 | 68 | return hsv; |
Bobty | 0:887096209439 | 69 | } |
Bobty | 0:887096209439 | 70 | |
Bobty | 0:887096209439 | 71 | if (rgbMax == rgb.r) |
Bobty | 0:887096209439 | 72 | hsv.h = 0 + 43 * (rgb.g - rgb.b) / (rgbMax - rgbMin); |
Bobty | 0:887096209439 | 73 | else if (rgbMax == rgb.g) |
Bobty | 0:887096209439 | 74 | hsv.h = 85 + 43 * (rgb.b - rgb.r) / (rgbMax - rgbMin); |
Bobty | 0:887096209439 | 75 | else |
Bobty | 0:887096209439 | 76 | hsv.h = 171 + 43 * (rgb.r - rgb.g) / (rgbMax - rgbMin); |
Bobty | 0:887096209439 | 77 | |
Bobty | 0:887096209439 | 78 | return hsv; |
Bobty | 0:887096209439 | 79 | } |