A somewhat silly project that uses an LPC11U24 to control the system, a Neopixel stick to provide light, and a sound FX board with a small speaker to make noise. I set the pins to inputs with pull-ups then connected 14 jumper wires to ground. Every time a wire was disconnected, the system changed its lighting pattern: color, blink timing, blink pattern (blink to white, black, random, or opposite the main color). The system also played a random audio clip. More details on http://embedded.fm/blog/2016/5/24/fistful-of-wires License: CC-A-NC

Dependencies:   PixelArray mbed

LedArrayController.h

Committer:
Elecia
Date:
2016-05-25
Revision:
1:0a051df78be2

File content as of revision 1:0a051df78be2:


#define NLED (8)
#define COLOR_WHITE 0xFFFFFF
#define COLOR_BLACK 0x000000

extern void AllOneColorLeds(neopixel::Pixel * out, uint32_t index, uintptr_t color);

class LedArrayController {
public:
    LedArrayController(BusIn *bus, neopixel::PixelArray *array) : mBus(bus), mArray(array)
    {
        mBus->mode(PullUp);
        
    }
    void Stop()
    {
            mTimer.detach();
    }
    void OnChangeMode(uint32_t baseColor)
    {
                                   // 000  001  010  011  100  101  110, 111
        const float mBlinkTiming[] = {1.0, 0.1, 0.5, 0.0, 2.0, 0.0, 0.0, 5.0};
        mBaseColor = baseColor;
        mIsBaseColor = false;
        mBehavior.value = *mBus;

        Update();

        mTiming = mBlinkTiming[mBehavior.timingIndex];
        if (mTiming > 0.0f)
        {
            mTimer.attach(this, &LedArrayController::Update, mTiming); 
        } else {
            mTimer.detach();
        }        
    }
    void Update() {
        // called by timer for updating LEDs:
        if (mIsBaseColor) 
        {
            switch (mBehavior.type) {
            case (BLINK_TO_WHITE):
                mArray->update(AllOneColorLeds, NLED, COLOR_WHITE);
                break;
            case (BLINK_TO_BLACK):
                mArray->update(AllOneColorLeds, NLED, COLOR_BLACK);
                break;
            case (BLINK_TO_RANDOM):
                mArray->update(AllOneColorLeds, NLED, (rand() & COLOR_WHITE));
                break;
            case (BLINK_TO_OPPOSITE):
                mArray->update(AllOneColorLeds, NLED, ~mBaseColor);
                break;
            }
            mIsBaseColor = false;

        } else {
           // set to base color
            mArray->update(AllOneColorLeds, NLED, mBaseColor);
            mIsBaseColor = true;           
        }     
        mTimer.attach(this, &LedArrayController::Update, mTiming); 
                   
    }
private:
    float mTiming;
    BusIn *mBus;
    neopixel::PixelArray *mArray;
    Timeout mTimer;
    bool mIsBaseColor;
    uint32_t mBaseColor;
    typedef enum {BLINK_TO_WHITE=0, BLINK_TO_BLACK=1, BLINK_TO_RANDOM=2, BLINK_TO_OPPOSITE=3 } eBlinkType;
    union {
        struct {
            uint32_t timingIndex:3;
            uint32_t type:2;
            uint32_t junk:28;
        };
        uint32_t value;            
   } mBehavior;
};