|
| 1 | +/* |
| 2 | + G35: An Arduino library for GE Color Effects G-35 holiday lights. |
| 3 | + Copyright © 2011 The G35 Authors. Use, modification, and distribution are |
| 4 | + subject to the BSD license as described in the accompanying LICENSE file. |
| 5 | +
|
| 6 | + By Mike Tsao <http://github.com/sowbug>. |
| 7 | +
|
| 8 | + See README for complete attributions. |
| 9 | +*/ |
| 10 | + |
| 11 | +#ifndef INCLUDE_G35_PROGRAMS_EYES_H |
| 12 | +#define INCLUDE_G35_PROGRAMS_EYES_H |
| 13 | + |
| 14 | +#include <LightProgram.h> |
| 15 | + |
| 16 | +class Eye { |
| 17 | + public: |
| 18 | + Eye() |
| 19 | + : color_(COLOR_BLACK), position_(0), next_blink_(0), state_(INIT) { |
| 20 | + switch (rand() % 4) { |
| 21 | + case 0: color_ = COLOR_ORANGE; break; |
| 22 | + case 1: color_ = COLOR_RED; break; |
| 23 | + case 2: color_ = COLOR_INDIGO; break; |
| 24 | + case 3: color_ = COLOR_GREEN; break; |
| 25 | + } |
| 26 | + } |
| 27 | + |
| 28 | + uint16_t get_position() { return position_; } |
| 29 | + void set_position(uint16_t value) { position_ = value; } |
| 30 | + |
| 31 | + void Do(G35& g35) { |
| 32 | + if (state_ == INIT) { |
| 33 | + state_ = WATCHING; |
| 34 | + } |
| 35 | + uint32_t now = millis(); |
| 36 | + if (next_blink_ < now) { |
| 37 | + if (state_ == BLINKING) { |
| 38 | + g35.fill_color(position_, 2, G35::MAX_INTENSITY, color_); |
| 39 | + next_blink_ = now + 3000 + (rand() % 3000); |
| 40 | + state_ = WATCHING; |
| 41 | + } else { |
| 42 | + g35.fill_color(position_, 2, G35::MAX_INTENSITY, COLOR_BLACK); |
| 43 | + next_blink_ = now + 100; |
| 44 | + state_ = BLINKING; |
| 45 | + } |
| 46 | + } |
| 47 | + } |
| 48 | + |
| 49 | + private: |
| 50 | + enum { |
| 51 | + INIT, WATCHING, BLINKING |
| 52 | + }; |
| 53 | + |
| 54 | + color_t color_; |
| 55 | + uint16_t position_; |
| 56 | + uint32_t next_blink_; |
| 57 | + uint8_t state_; |
| 58 | +}; |
| 59 | + |
| 60 | +class Eyes : public LightProgram { |
| 61 | + public: |
| 62 | + Eyes(G35& g35); |
| 63 | + uint32_t Do(); |
| 64 | + |
| 65 | + private: |
| 66 | + enum { EYE_COUNT = 10 }; |
| 67 | + |
| 68 | + uint8_t count_; |
| 69 | + uint32_t next_eye_; |
| 70 | + Eye eyes_[EYE_COUNT]; |
| 71 | +}; |
| 72 | + |
| 73 | +#endif // INCLUDE_G35_PROGRAMS_EYES_H |
0 commit comments