Changeset - 03483f073427
[Not reviewed]
default
0 1 0
Dennis Fink - 6 years ago 2018-02-17 00:37:25
dennis.fink@c3l.lu
Add DoubleSet method
1 file changed with 17 insertions and 15 deletions:
0 comments (0 inline, 0 general)
Neopixel_Goggles.ino
Show inline comments
 
@@ -118,123 +118,120 @@ class NeoPatterns : public Adafruit_NeoP
 
    }
 

	
 
    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);
 
      DoubleSet(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);
 
        uint32_t c;
 
        if (i == Index || i == TotalSteps - Index) {
 
          c = PixelColor;
 
        }
 
        else {
 
          setPixelColor(i, DimColor(getPixelColor(i)));
 
          c = DimColor(getPixelColor(i));
 
        }
 
        setPixelColor(i, c);
 
      }
 
      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++) {
 
        uint32_t c;
 
        if (i == Index) {
 
          setPixelColor(i, PixelColor); // First Eye
 
          setPixelColor(numPixels() - 1 - i, PixelColor); // Second Eye
 
          c = PixelColor;
 
        }
 
        else {
 
          setPixelColor(i, DimColor(getPixelColor(i)));
 
          setPixelColor(numPixels() - 1 - i, DimColor(getPixelColor(i)));
 
          c = DimColor(getPixelColor(i));
 
        }
 
        DoubleSet(i, c);
 
      }
 
      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);
 
      int i = random(numPixels() / 2); // this saves 4 bytes instead of calling random in the function call of DoubleSet
 
      DoubleSet(i, PixelColor);
 
      Increment();
 
    }
 

	
 
    void Blink(uint32_t color, uint16_t steps, uint16_t interval) {
 
      ActivePattern = BLINK;
 
      Interval = interval;
 
      if (steps % 2 != 0) {
 
        steps++;
 
      }
 
      TotalSteps = steps;
 
      PixelColor = color;
 
      Index = 0;
 
    }
 

	
 
    void BlinkUpdate() {
 
      uint32_t c;
 
      if (Index % 2 == 0) {
 
        c = PixelColor;
 
      } else {
 
        c = Color(0, 0, 0);
 
      }
 
      ColorSet(c);
 
      Increment();
 
    }
 
@@ -257,48 +254,53 @@ class NeoPatterns : public Adafruit_NeoP
 
    uint32_t DimColor(uint32_t color) {
 
      return Color(((color >> 16) & 0xFF) >> 1, ((color >> 8) & 0xFF) >> 1, (color & 0xFF) >> 1);
 
    }
 

	
 
    uint32_t Wheel(byte WheelPos) {
 
      WheelPos = 255 - WheelPos;
 
      if (WheelPos < 85) {
 
        return Color(255 - WheelPos * 3, 0, WheelPos * 3);
 
      }
 
      else if (WheelPos < 170) {
 
        WheelPos -= 85;
 
        return Color(0, WheelPos * 3, 255 - WheelPos * 3);
 
      }
 
      else {
 
        WheelPos -= 170;
 
        return Color(WheelPos * 3, 255 - WheelPos * 3, 0);
 
      }
 
    }
 

	
 
    void ColorSet(uint32_t color) {
 
      for (int i = 0; i < numPixels(); i++) {
 
        setPixelColor(i, color);
 
      }
 
    }
 

	
 
    void DoubleSet(uint16_t i, uint32_t color) {
 
      setPixelColor(i, color);
 
      setPixelColor(numPixels() - 1 - i, color);
 
    }
 
};
 

	
 
void RingsComplete();
 

	
 
NeoPatterns Rings(32, PIN, NEO_GRB + NEO_KHZ800, &RingsComplete);
 
uint8_t mode = 0;
 
uint32_t prev_time;
 

	
 
void setup() {
 
#ifdef __AVR_ATtiny85__
 
  if (F_CPU == 16000000) clock_prescale_set(clock_div_1);
 
#endif
 
  Rings.begin();
 
  Rings.setBrightness(BRIGHTNESS);
 
  Rings.RainbowCycle(random(RAINBOW_CYCLE_MIN_INTERVAL, RAINBOW_CYCLE_MAX_INTERVAL + 1));
 
  prev_time = millis();
 
}
 

	
 
void loop() {
 
  Rings.Update();
 
  /*
 
     We could store the return of the first millis call in a variable.
 
     But this routine is fast, so we only loose some milliseconds (if even)
 
     and we are not that time critical, that the MODE changes extacly after
0 comments (0 inline, 0 general)