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
LedArrayController.h@1:0a051df78be2, 2016-05-25 (annotated)
- Committer:
- Elecia
- Date:
- Wed May 25 03:42:25 2016 +0000
- Revision:
- 1:0a051df78be2
As demonstrated at Bring-A-Hack.
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
Elecia | 1:0a051df78be2 | 1 | |
Elecia | 1:0a051df78be2 | 2 | #define NLED (8) |
Elecia | 1:0a051df78be2 | 3 | #define COLOR_WHITE 0xFFFFFF |
Elecia | 1:0a051df78be2 | 4 | #define COLOR_BLACK 0x000000 |
Elecia | 1:0a051df78be2 | 5 | |
Elecia | 1:0a051df78be2 | 6 | extern void AllOneColorLeds(neopixel::Pixel * out, uint32_t index, uintptr_t color); |
Elecia | 1:0a051df78be2 | 7 | |
Elecia | 1:0a051df78be2 | 8 | class LedArrayController { |
Elecia | 1:0a051df78be2 | 9 | public: |
Elecia | 1:0a051df78be2 | 10 | LedArrayController(BusIn *bus, neopixel::PixelArray *array) : mBus(bus), mArray(array) |
Elecia | 1:0a051df78be2 | 11 | { |
Elecia | 1:0a051df78be2 | 12 | mBus->mode(PullUp); |
Elecia | 1:0a051df78be2 | 13 | |
Elecia | 1:0a051df78be2 | 14 | } |
Elecia | 1:0a051df78be2 | 15 | void Stop() |
Elecia | 1:0a051df78be2 | 16 | { |
Elecia | 1:0a051df78be2 | 17 | mTimer.detach(); |
Elecia | 1:0a051df78be2 | 18 | } |
Elecia | 1:0a051df78be2 | 19 | void OnChangeMode(uint32_t baseColor) |
Elecia | 1:0a051df78be2 | 20 | { |
Elecia | 1:0a051df78be2 | 21 | // 000 001 010 011 100 101 110, 111 |
Elecia | 1:0a051df78be2 | 22 | const float mBlinkTiming[] = {1.0, 0.1, 0.5, 0.0, 2.0, 0.0, 0.0, 5.0}; |
Elecia | 1:0a051df78be2 | 23 | mBaseColor = baseColor; |
Elecia | 1:0a051df78be2 | 24 | mIsBaseColor = false; |
Elecia | 1:0a051df78be2 | 25 | mBehavior.value = *mBus; |
Elecia | 1:0a051df78be2 | 26 | |
Elecia | 1:0a051df78be2 | 27 | Update(); |
Elecia | 1:0a051df78be2 | 28 | |
Elecia | 1:0a051df78be2 | 29 | mTiming = mBlinkTiming[mBehavior.timingIndex]; |
Elecia | 1:0a051df78be2 | 30 | if (mTiming > 0.0f) |
Elecia | 1:0a051df78be2 | 31 | { |
Elecia | 1:0a051df78be2 | 32 | mTimer.attach(this, &LedArrayController::Update, mTiming); |
Elecia | 1:0a051df78be2 | 33 | } else { |
Elecia | 1:0a051df78be2 | 34 | mTimer.detach(); |
Elecia | 1:0a051df78be2 | 35 | } |
Elecia | 1:0a051df78be2 | 36 | } |
Elecia | 1:0a051df78be2 | 37 | void Update() { |
Elecia | 1:0a051df78be2 | 38 | // called by timer for updating LEDs: |
Elecia | 1:0a051df78be2 | 39 | if (mIsBaseColor) |
Elecia | 1:0a051df78be2 | 40 | { |
Elecia | 1:0a051df78be2 | 41 | switch (mBehavior.type) { |
Elecia | 1:0a051df78be2 | 42 | case (BLINK_TO_WHITE): |
Elecia | 1:0a051df78be2 | 43 | mArray->update(AllOneColorLeds, NLED, COLOR_WHITE); |
Elecia | 1:0a051df78be2 | 44 | break; |
Elecia | 1:0a051df78be2 | 45 | case (BLINK_TO_BLACK): |
Elecia | 1:0a051df78be2 | 46 | mArray->update(AllOneColorLeds, NLED, COLOR_BLACK); |
Elecia | 1:0a051df78be2 | 47 | break; |
Elecia | 1:0a051df78be2 | 48 | case (BLINK_TO_RANDOM): |
Elecia | 1:0a051df78be2 | 49 | mArray->update(AllOneColorLeds, NLED, (rand() & COLOR_WHITE)); |
Elecia | 1:0a051df78be2 | 50 | break; |
Elecia | 1:0a051df78be2 | 51 | case (BLINK_TO_OPPOSITE): |
Elecia | 1:0a051df78be2 | 52 | mArray->update(AllOneColorLeds, NLED, ~mBaseColor); |
Elecia | 1:0a051df78be2 | 53 | break; |
Elecia | 1:0a051df78be2 | 54 | } |
Elecia | 1:0a051df78be2 | 55 | mIsBaseColor = false; |
Elecia | 1:0a051df78be2 | 56 | |
Elecia | 1:0a051df78be2 | 57 | } else { |
Elecia | 1:0a051df78be2 | 58 | // set to base color |
Elecia | 1:0a051df78be2 | 59 | mArray->update(AllOneColorLeds, NLED, mBaseColor); |
Elecia | 1:0a051df78be2 | 60 | mIsBaseColor = true; |
Elecia | 1:0a051df78be2 | 61 | } |
Elecia | 1:0a051df78be2 | 62 | mTimer.attach(this, &LedArrayController::Update, mTiming); |
Elecia | 1:0a051df78be2 | 63 | |
Elecia | 1:0a051df78be2 | 64 | } |
Elecia | 1:0a051df78be2 | 65 | private: |
Elecia | 1:0a051df78be2 | 66 | float mTiming; |
Elecia | 1:0a051df78be2 | 67 | BusIn *mBus; |
Elecia | 1:0a051df78be2 | 68 | neopixel::PixelArray *mArray; |
Elecia | 1:0a051df78be2 | 69 | Timeout mTimer; |
Elecia | 1:0a051df78be2 | 70 | bool mIsBaseColor; |
Elecia | 1:0a051df78be2 | 71 | uint32_t mBaseColor; |
Elecia | 1:0a051df78be2 | 72 | typedef enum {BLINK_TO_WHITE=0, BLINK_TO_BLACK=1, BLINK_TO_RANDOM=2, BLINK_TO_OPPOSITE=3 } eBlinkType; |
Elecia | 1:0a051df78be2 | 73 | union { |
Elecia | 1:0a051df78be2 | 74 | struct { |
Elecia | 1:0a051df78be2 | 75 | uint32_t timingIndex:3; |
Elecia | 1:0a051df78be2 | 76 | uint32_t type:2; |
Elecia | 1:0a051df78be2 | 77 | uint32_t junk:28; |
Elecia | 1:0a051df78be2 | 78 | }; |
Elecia | 1:0a051df78be2 | 79 | uint32_t value; |
Elecia | 1:0a051df78be2 | 80 | } mBehavior; |
Elecia | 1:0a051df78be2 | 81 | }; |
Elecia | 1:0a051df78be2 | 82 |