Demo entry 6780831

1

   

Submitted by anonymous on Dec 29, 2018 at 14:03
Language: Arduino. Code size: 5.4 kB.

#include <Adafruit_NeoPixel.h>
#define PIN_1 7
#define PIN_2 8

#define PIN_3 6

// Parameter 1 = number of pixels in strip
// Parameter 2 = pin number (most are valid)
// Parameter 3 = pixel type flags, add together as needed:
//   NEO_KHZ800  800 KHz bitstream (most NeoPixel products w/WS2812 LEDs)
//   NEO_KHZ400  400 KHz (classic 'v1' (not v2) FLORA pixels, WS2811 drivers)
//   NEO_GRB     Pixels are wired for GRB bitstream (most NeoPixel products)
//   NEO_RGB     Pixels are wired for RGB bitstream (v1 FLORA pixels, not v2)
Adafruit_NeoPixel strip1 = Adafruit_NeoPixel(8, PIN_1, NEO_GRB + NEO_KHZ800);
Adafruit_NeoPixel strip2 = Adafruit_NeoPixel(8, PIN_2, NEO_GRB + NEO_KHZ800);

Adafruit_NeoPixel strip3 = Adafruit_NeoPixel(60, PIN_3, NEO_GRB + NEO_KHZ800);

void setup() {
  Serial.begin(9600);
  // put your setup code here, to run once:
  strip1.begin();
  strip1.show(); // Initialize all pixels to 'off'

  strip2.begin();
  strip2.show(); // Initialize all pixels to 'off'

  strip3.begin();
  strip3.show(); // Initialize all pixels to 'off'
  
}

long iType = 0;

void loop() {
  long iBright = random(0, 255);

  for(int i = 0; i < 8; i++)
  {
    switch(iType)
    {
      case 0:
      SetRed(i, iBright);
      break;
      case 1:
      SetBlue(i, iBright);
      break;
      case 2:
      SetALL(i, iBright);
      break;      
    }
  }

  //SetRGB_60();

  //colorWipe(strip3.Color(255, 0, 0), 50); // Red
  //colorWipe(strip3.Color(0, 255, 0), 50); // Green
  //colorWipe(strip3.Color(0, 0, 255), 50); // Blue

  //rainbow(20);  
  rainbowCycle(50);
  //theaterChaseRainbow(50);
  
  delay(5000);

  Serial.println(iType);

  if (iType >= 2)
    iType = 0;
  else     
    iType++;
}

void SetRed(int i, long iBright)
{
    strip1.setPixelColor(i, 255, 0, 0);
    strip1.setBrightness(iBright);
    strip1.show(); // Initialize all pixels to 'off'
    strip2.setPixelColor(i, 0, 0, 0);
    strip2.show(); // Initialize all pixels to 'off'
}

void SetBlue(int i, long iBright)
{
    strip2.setPixelColor(i, 0, 0, 255);
    strip2.setBrightness(iBright);
    strip2.show(); // Initialize all pixels to 'off'
    strip1.setPixelColor(i, 0, 0, 0);
    strip1.show(); // Initialize all pixels to 'off'
}

void SetALL(int i, long iBright)
{
    long iRed  = random(0, 255);    
    long iGreen = random(0, 255);    
    long iBlue = random(0, 255);
    
    strip1.setPixelColor(i, iRed, iGreen, iBlue);
    strip1.setBrightness(iBright);
    strip1.show(); // Initialize all pixels to 'off'
      
    strip2.setPixelColor(i, iRed, iGreen, iBlue);
    strip2.setBrightness(iBright);
    strip2.show(); // Initialize all pixels to 'off'
}

void SetRGB_60()
{
  long iBright = random(0, 255);

  for(int i = 0; i < 60; i++)
  {  
    long iRed  = random(0, 255);    
    long iGreen = random(0, 255);    
    long iBlue = random(0, 255);
    
    strip3.setPixelColor(i, iRed, iGreen, iBlue);    
    strip2.setBrightness(iBright);
    strip3.show(); // Initialize all pixels to 'off'
    delay(80);
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  if(WheelPos < 85) {
   return strip3.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
  } else if(WheelPos < 170) {
   WheelPos -= 85;
   return strip3.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  } else {
   WheelPos -= 170;
   return strip3.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
}

// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip3.numPixels(); i++) {
      strip3.setPixelColor(i, c);
      strip3.show();
      delay(wait);
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip3.numPixels(); i++) {
      strip3.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip3.show();
    delay(wait);
  }
}

void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip3.numPixels(); i++) {
      strip3.setPixelColor(i, Wheel(((i * 256 / strip3.numPixels()) + j) & 255));
    }
    strip3.show();
    delay(wait);
  }
}

void theaterChase(uint32_t c, uint8_t wait) {
  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (int i=0; i < strip3.numPixels(); i=i+3) {
        strip3.setPixelColor(i+q, c);    //turn every third pixel on
      }
      strip3.show();

      delay(wait);

      for (int i=0; i < strip3.numPixels(); i=i+3) {
        strip3.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
        for (int i=0; i < strip3.numPixels(); i=i+3) {
          strip3.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on
        }
        strip3.show();

        delay(wait);

        for (int i=0; i < strip3.numPixels(); i=i+3) {
          strip3.setPixelColor(i+q, 0);        //turn every third pixel off
        }
    }
  }
}

This snippet took 0.01 seconds to highlight.

Back to the Entry List or Home.

Delete this entry (admin only).