Changeset - 6ca9558755f3
[Not reviewed]
default
0 1 0
Dennis Fink - 7 years ago 2018-02-06 23:13:24
dennis.fink@c3l.lu
Change comments
1 file changed with 3 insertions and 4 deletions:
0 comments (0 inline, 0 general)
Neopixel_Goggles.ino
Show inline comments
 
#include <Adafruit_NeoPixel.h>
 

	
 
#ifdef __AVR_ATtiny85__ // Trinket, Gemma, etc.
 
#ifdef __AVR_ATtiny85__
 
#include <avr/power.h>
 
#endif
 

	
 
/* Begin config section
 
-----------------------*/
 
// Begin config section
 

	
 
#define PIN 0
 

	
 
#define BRIGHTNESS 64
 

	
 
#define MODE_CHANGE_TIME 10000
 

	
 
#define COLOR_MIN 0
 
#define COLOR_MAX 255
 

	
 
#define STEPS_MIN 5
 
#define STEPS_MAX 10
 

	
 
#define SLOW_INTERVAL_MIN 25
 
#define SLOW_INTERVAL_MAX 55
 

	
 
#define RAINBOW_CYCLE_MIN_INTERVAL 1
 
#define RAINBOW_CYCLE_MAX_INTERVAL 10
 

	
 
#define BLINK_MIN_INTERVAL 250
 
#define BLINK_MAX_INTERVAL 500
 

	
 
/* End config section */
 
// End config section
 

	
 
enum  pattern {
 
  RAINBOW_CYCLE,
 
  COLOR_WIPE,
 
  DOUBLE_COLOR_WIPE,
 
  SCANNER,
 
  DOUBLE_SCANNER,
 
  RANDOM,
 
  DOUBLE_RANDOM,
 
  BLINK,
 
  DOT
 
};
 

	
 
class NeoPatterns : public Adafruit_NeoPixel {
 
  public:
 
    pattern  ActivePattern;
 

	
 
    uint16_t Interval;
 
    unsigned long lastUpdate;
 
    uint32_t PixelColor;
 
    uint16_t TotalSteps;
 
    uint16_t Index;
 

	
 
    void (*OnComplete)();
 

	
 
    NeoPatterns(uint16_t pixels, uint8_t pin, uint8_t type, void (*callback)()) : Adafruit_NeoPixel(pixels, pin, type) {
 
      OnComplete = callback;
 
    }
 

	
 
    void Update() {
 
      if ((millis() - lastUpdate) > Interval) {
 
        lastUpdate = millis();
 
        switch (ActivePattern) {
 
          case RAINBOW_CYCLE:
 
            RainbowCycleUpdate();
 
            break;
 
          case COLOR_WIPE:
 
            ColorWipeUpdate();
 
            break;
 
          case DOUBLE_COLOR_WIPE:
 
            DoubleColorWipeUpdate();
 
            break;
 
          case SCANNER:
 
            ScannerUpdate();
 
            break;
 
          case DOUBLE_SCANNER:
 
            DoubleScannerUpdate();
 
            break;
 
          case RANDOM:
 
            RandomUpdate();
 
            break;
 
          case DOUBLE_RANDOM:
 
            DoubleRandomUpdate();
 
            break;
 
          case BLINK:
 
            BlinkUpdate();
 
            break;
 
          case DOT:
 
            DotUpdate();
 
            break;
 
          default:
 
            break;
 
        }
 
      }
 
    }
 

	
 
    void Increment() {
 
      show();
 
      Index++;
 
      if (Index >= TotalSteps) {
 
        Index = 0;
 
        OnComplete();
 
      }
 
    }
 

	
 
    void RainbowCycle(uint16_t interval) {
 
      ActivePattern = RAINBOW_CYCLE;
 
      Interval = interval;
 
      TotalSteps = 255;
 
      Index = 0;
 
    }
 

	
 
    void RainbowCycleUpdate() {
 
      for (int i = 0; i < numPixels(); i++) {
 
        setPixelColor(i, Wheel(((i * 256 / numPixels()) + Index) & 255));
 
      }
 
      Increment();
 
    }
 

	
 
    void ColorWipe(uint32_t color, uint16_t interval) {
 
      ActivePattern = COLOR_WIPE;
 
      Interval = interval;
 
      TotalSteps = numPixels();
 
      PixelColor = color;
 
      Index = 0;
 
    }
 

	
 
    void ColorWipeUpdate() {
 
      setPixelColor(Index, PixelColor);
 
      Increment();
 
    }
 

	
 
    void DoubleColorWipe(uint32_t color, uint16_t interval) {
 
      ActivePattern = DOUBLE_COLOR_WIPE;
 
      Interval = interval;
 
      TotalSteps = numPixels() / 2;
 
      PixelColor = color;
 
      Index = 0;
 
    }
 

	
 
    void DoubleColorWipeUpdate() {
 
      setPixelColor(Index, PixelColor);
 
      setPixelColor(numPixels() - 1 - Index, PixelColor);
 
      Increment();
 
    }
 

	
 
    void Scanner(uint32_t color, uint16_t interval) {
 
      ActivePattern = SCANNER;
 
      Interval = interval;
 
      TotalSteps = (numPixels() - 1) * 2;
 
      PixelColor = color;
 
      Index = 0;
 
    }
 

	
 
    void ScannerUpdate() {
 
      for (int i = 0; i < numPixels(); i++) {
 
        if (i == Index) {
 
          setPixelColor(i, PixelColor);
 
        }
 
        else if (i == TotalSteps - Index)  {
 
          setPixelColor(i, PixelColor);
 
        }
 
        else {
 
          setPixelColor(i, DimColor(getPixelColor(i)));
 
        }
 
      }
 
      Increment();
 
    }
 

	
 
    void DoubleScanner(uint32_t color, uint16_t interval) {
 
      ActivePattern = DOUBLE_SCANNER;
 
      Interval = interval;
 
      TotalSteps = (numPixels() / 2);
 
      PixelColor = color;
 
      Index = 0;
 
    }
 

	
 
    void DoubleScannerUpdate() {
 
      for (int i = 0; i < numPixels() / 2; i++) {
 
        if (i == Index) {
 
          setPixelColor(i, PixelColor); // First Eye
 
          setPixelColor(numPixels() - 1 - i, PixelColor); // Second Eye
 
        }
 
        else {
 
          setPixelColor(i, DimColor(getPixelColor(i)));
 
          setPixelColor(numPixels() - 1 - i, DimColor(getPixelColor(i)));
 
        }
 
      }
 
      Increment();
 
    }
 

	
 
    void Random(uint32_t color, uint16_t steps, uint16_t interval) {
 
      ActivePattern = RANDOM;
 
      Interval = interval;
 
      TotalSteps = steps;
 
      PixelColor = color;
 
      Index = 0;
 
    }
 

	
 
    void RandomUpdate() {
 
      setPixelColor(random(numPixels()), PixelColor);
 
      Increment();
 
    }
 

	
 
    void DoubleRandom(uint32_t color, uint16_t steps, uint16_t interval) {
 
      ActivePattern = DOUBLE_RANDOM;
 
      Interval = interval;
 
      TotalSteps = steps;
 
      PixelColor = color;
 
      Index = 0;
 
    }
 

	
 
    void DoubleRandomUpdate() {
 
      int i = random(numPixels() / 2);
 
      setPixelColor(i, PixelColor);
 
      setPixelColor(numPixels() - 1 - i, PixelColor);
 
      Increment();
 
    }
 

	
 
    void Blink(uint32_t color, uint16_t steps, uint16_t interval) {
 
      ActivePattern = BLINK;
 
      Interval = interval;
0 comments (0 inline, 0 general)