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/

Revision:
1:362331cec9b7
Parent:
0:887096209439
Child:
2:99eb4c6e9ea4
--- a/ledstrip.cpp	Tue Aug 18 16:03:29 2015 +0000
+++ b/ledstrip.cpp	Thu Aug 20 07:41:02 2015 +0000
@@ -1,3 +1,7 @@
+// LED Strip using WS2801 with two ISRs for two SPI connected 
+// LED strips running in parallel
+// Rob Dobson 2013-2014
+
 #include "ledstrip.h"
 #include "colourconverters.h"
 #include "stddef.h"
@@ -6,50 +10,51 @@
 #define SSP_IMSC_TX_RDY 3
 #define SSP_IMSC_BITMASK 0x0f
 
-volatile int mCurPos0;
-int mEndPos0;
-volatile int mCurPos1;
-int mEndPos1;
-volatile bool mShowingLeds0;
-volatile bool mShowingLeds1;
-unsigned char* pLedValues;
-bool inISR;
+volatile int mCurPos0 = 0;
+int mEndPos0 = 0;
+volatile bool isr0Busy = false;
+unsigned char* pLedValues0 = NULL;
 
 extern "C" void spi0_isr()
 {
     if (mCurPos0 < mEndPos0)
     {
-        LPC_SSP0->DR = pLedValues[mCurPos0];  // write to FIFO data register
+        LPC_SSP0->DR = pLedValues0[mCurPos0];  // write to FIFO data register
         mCurPos0++;
     }
     else
     {
         // Turn off interrupts
         LPC_SSP0->IMSC = 0;
-        mShowingLeds0 = false;
+        isr0Busy = false;
     }
 }
 
+volatile int mCurPos1 = 0;
+int mEndPos1 = 0;
+volatile bool isr1Busy = false;
+unsigned char* pLedValues1 = NULL;
+
 extern "C" void spi1_isr()
 {
     if (mCurPos1 < mEndPos1)
     {
-        LPC_SSP1->DR = pLedValues[mCurPos1];  // write to FIFO data register
+        LPC_SSP1->DR = pLedValues1[mCurPos1];  // write to FIFO data register
         mCurPos1++;
     }
     else
     {
         // Turn off interrupts
         LPC_SSP1->IMSC = 0;
-        mShowingLeds1 = false;
+        isr1Busy = false;
     }
 }
 
 ledstrip::ledstrip(int length, int splitPoint)
 {
-    mpLedValuesA = 0;
-    mpLedValuesB = 0;
-    mpCurLedValues = 0;
+    mpLedValuesA = NULL;
+    mpLedValuesB = NULL;
+    mpCurLedValues = NULL;
 
     // SPI0 (using SSP 0 in 1768 chip)
     mpSPI0 = new SPI(p11, NC, p13);
@@ -70,10 +75,7 @@
     NVIC_ClearPendingIRQ(SSP1_IRQn);
     NVIC_SetPriority(SSP1_IRQn, 2);
     NVIC_EnableIRQ(SSP1_IRQn);
-    
-    // Enable interrupts
-    __enable_irq();
-        
+
     // Resize the string length
     Resize(length, splitPoint);
 }
@@ -86,11 +88,11 @@
 
 bool ledstrip::Resize(int length, int splitPoint)
 {
-    if (mShowingLeds0 || mShowingLeds1)
+    if (isr0Busy || isr1Busy)
         return false;
-    if (mpLedValuesA != 0)
+    if (mpLedValuesA != NULL)
         delete mpLedValuesA;
-    if (mpLedValuesB != 0)
+    if (mpLedValuesB != NULL)
         delete mpLedValuesB;
     mLedsBufSize = length*mColoursPerLed;
     mpLedValuesA = new unsigned char[mLedsBufSize];
@@ -131,9 +133,20 @@
 
 bool ledstrip::IsBusy()
 {
-    return mShowingLeds0 || mShowingLeds1;
+    return isr0Busy || isr1Busy;
 }
 
+void ledstrip::RawFill(int startLed, int numLeds, const unsigned char* pLedVals)
+{
+    if ((startLed < 0) || (startLed >= mLedsInStrip))
+        return;
+    if (numLeds >= mLedsInStrip - startLed)
+        numLeds = mLedsInStrip - startLed;
+    int pos = startLed * mColoursPerLed;
+    unsigned char* pBuf = GetBuffer() + pos;
+    memcpy(pBuf, pLedVals, numLeds * mColoursPerLed);
+}
+    
 // Fill - solid colour
 void ledstrip::Fill(int startLed, int numLeds, 
                 int r1, int g1, int b1)
@@ -218,13 +231,12 @@
     */
 }
 
-    
 void ledstrip::ShowLeds()
 {
     // Check if busy
-    while (mShowingLeds0 || mShowingLeds1)
-        ;
-    wait_us(750);
+    while (isr0Busy || isr1Busy)
+        wait_us(2000);
+    wait_us(2000);
     
     // Set up start points
     mCurPos0 = 0;
@@ -233,53 +245,28 @@
     mEndPos1 = mLedsInStrip*mColoursPerLed;
     
     // Set the buffer for the ISRs
-    pLedValues = mpCurLedValues;
-    
+    pLedValues0 = mpCurLedValues;
+    pLedValues1 = mpCurLedValues;
+
     // Flip the current buffer to the alternate one for interleaved writing
     if (mpCurLedValues == mpLedValuesA)
+    {
+        memcpy(mpLedValuesB, mpLedValuesA, mLedsBufSize);
         mpCurLedValues = mpLedValuesB;
+    }
     else
+    {
+        memcpy(mpLedValuesA, mpLedValuesB, mLedsBufSize);
         mpCurLedValues = mpLedValuesA;
+    }
     
     // Enable interrupts
-    mShowingLeds0 = true;
-    LPC_SSP0->IMSC = (1 << SSP_IMSC_TX_RDY) & SSP_IMSC_BITMASK;
+    isr0Busy = true;
+    if (mSplitPoint < mLedsInStrip)
+        isr1Busy = true;
     
     // Check if second strip is used
+    LPC_SSP0->IMSC = (1 << SSP_IMSC_TX_RDY) & SSP_IMSC_BITMASK;
     if (mSplitPoint < mLedsInStrip)
-    {
         LPC_SSP1->IMSC = (1 << SSP_IMSC_TX_RDY) & SSP_IMSC_BITMASK;
-        mShowingLeds1 = true;
-    }
- //   for (int q = 0; q < mLedsInStrip*3; q+=3)
- //       printf("%d %02x%02x%02x\n", q/3, mpLedValues[q], mpLedValues[q+1], mpLedValues[q+2]);
-/*
-    int pos1 = 0;
-    int pos2 = mSplitPoint * mColoursPerLed;
-    for (int j = 0; j < mMaxChainLength; j++)
-    {
-        for (int k = 0; k < mColoursPerLed; k++)
-        {
-            unsigned char tval1 = 0;
-            if (pos1 + k < mLedsBufSize)
-                tval1 = mpLedValues[pos1 + k];
-            unsigned char tval2 = 0;
-            if (pos2 + k < mLedsBufSize)
-                tval2 = mpLedValues[pos2 + k];
-            for (int i = 0; i < 8; i++)
-            {
-                dat1 = (tval1 & 0x80) != 0;
-                tval1 = tval1 << 1;
-                dat2 = (tval2 & 0x80) != 0;
-                tval2 = tval2 << 1;
-                clk = 1;
-                clk = 0;
-                wait_us(1);
-            }
-        }
-        pos1 += mColoursPerLed;
-        pos2 += mColoursPerLed;
-    }
-    wait_us(750);
-*/
 }