Philip Walne
/
335_project
Dotstar LED demonstration, with stacker game. Uses 2 buttons, and LPC1768 microcontroller
modes/light_show.h@1:37200a0da529, 2017-01-04 (annotated)
- Committer:
- pwalne
- Date:
- Wed Jan 04 20:55:18 2017 +0000
- Revision:
- 1:37200a0da529
- Parent:
- 0:9ab173ff6353
Working version with DotStar LED
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
pwalne | 0:9ab173ff6353 | 1 | #ifndef _LIGHT_SHOW_H |
pwalne | 0:9ab173ff6353 | 2 | #define _LIGHT_SHOW_H |
pwalne | 0:9ab173ff6353 | 3 | |
pwalne | 0:9ab173ff6353 | 4 | #include <../light_game.h> |
pwalne | 0:9ab173ff6353 | 5 | |
pwalne | 0:9ab173ff6353 | 6 | class Light_Show : public Light_Game { |
pwalne | 0:9ab173ff6353 | 7 | public: |
pwalne | 0:9ab173ff6353 | 8 | Light_Show() {} |
pwalne | 0:9ab173ff6353 | 9 | virtual void init() { |
pwalne | 0:9ab173ff6353 | 10 | tail = -10; |
pwalne | 0:9ab173ff6353 | 11 | head = 0; |
pwalne | 0:9ab173ff6353 | 12 | int i; |
pwalne | 0:9ab173ff6353 | 13 | speed = 0.6; //1 second delay |
pwalne | 0:9ab173ff6353 | 14 | color = 0xFF0000; |
pwalne | 0:9ab173ff6353 | 15 | for(i = 0; i < 30; i++) //reset all lights! |
pwalne | 0:9ab173ff6353 | 16 | strip.setPixelColor(i, 0, 0, 0); |
pwalne | 0:9ab173ff6353 | 17 | strip.show(); |
pwalne | 0:9ab173ff6353 | 18 | wait(0.5); |
pwalne | 0:9ab173ff6353 | 19 | } |
pwalne | 0:9ab173ff6353 | 20 | virtual void update() { |
pwalne | 0:9ab173ff6353 | 21 | strip.setPixelColor(head, (uint8_t) (color >> 16), (uint8_t) (color >> 8), (uint8_t) color); |
pwalne | 0:9ab173ff6353 | 22 | strip.setPixelColor(tail, 0, 0, 0); |
pwalne | 0:9ab173ff6353 | 23 | strip.show(); |
pwalne | 0:9ab173ff6353 | 24 | wait(speed); |
pwalne | 0:9ab173ff6353 | 25 | if(++head >= 30) { |
pwalne | 0:9ab173ff6353 | 26 | head = 0; |
pwalne | 0:9ab173ff6353 | 27 | if((color >>= 8) == 0) // Next color (R->G->B) ... past blue now? |
pwalne | 0:9ab173ff6353 | 28 | color = 0xFF0000; |
pwalne | 0:9ab173ff6353 | 29 | } |
pwalne | 0:9ab173ff6353 | 30 | if(++tail >= 30) tail = 0; |
pwalne | 0:9ab173ff6353 | 31 | } |
pwalne | 0:9ab173ff6353 | 32 | |
pwalne | 0:9ab173ff6353 | 33 | virtual void btn1() { |
pwalne | 0:9ab173ff6353 | 34 | if((color >>= 2) == 0) |
pwalne | 0:9ab173ff6353 | 35 | color = 0xFF0000; |
pwalne | 0:9ab173ff6353 | 36 | } |
pwalne | 0:9ab173ff6353 | 37 | |
pwalne | 0:9ab173ff6353 | 38 | virtual void btn2() { |
pwalne | 0:9ab173ff6353 | 39 | speed -= 0.03; |
pwalne | 0:9ab173ff6353 | 40 | if(speed <= 0.00) |
pwalne | 0:9ab173ff6353 | 41 | speed = 1.00; |
pwalne | 0:9ab173ff6353 | 42 | } |
pwalne | 0:9ab173ff6353 | 43 | |
pwalne | 0:9ab173ff6353 | 44 | virtual bool isFinished() { return false; } |
pwalne | 0:9ab173ff6353 | 45 | |
pwalne | 0:9ab173ff6353 | 46 | private: |
pwalne | 0:9ab173ff6353 | 47 | float speed; |
pwalne | 0:9ab173ff6353 | 48 | uint32_t color; |
pwalne | 0:9ab173ff6353 | 49 | int tail, head; |
pwalne | 0:9ab173ff6353 | 50 | |
pwalne | 0:9ab173ff6353 | 51 | }; |
pwalne | 0:9ab173ff6353 | 52 | #endif |