Taal:

 

Leuke verlichting voor het naambord.

#include <Adafruit_NeoPixel.h> #include "WS2812_Definitions.h" #define PIN 0 #define LED_COUNT 52 int tel = 1; unsigned long led_color[LED_COUNT]; // Create an instance of the Adafruit_NeoPixel class called "leds". // That'll be what we refer to from here on... Adafruit_NeoPixel leds = Adafruit_NeoPixel(LED_COUNT, PIN, NEO_GRB + NEO_KHZ800); void setup() {  for (int i = 0; i < LED_COUNT; i = i + 2)  {    led_color[i] = RED;  }  leds.begin();  // Call this to start up the LED strip.  clearLEDs();   // This function, defined below, turns all LEDs off...  leds.show();   // ...but the LEDs don't actually update until you call this. } void loop() {  // A light shower of spring green rain----------------------------------------------------------------------------  // This will run the cascade from top->bottom 20 times  for (int i = 0; i < 5; i++)  {    // First parameter is the color, second is direction, third is ms between falls    looplichtRGB(10);    delay(500);  }  // A light shower of spring green rain----------------------------------------------------------------------------  // This will run the cascade from top->bottom 20 times  for (int i = 0; i < 5; i++)  {    // First parameter is the color, second is direction, third is ms between falls    arjan(RED, GREEN, BLUE, TOP_DOWN, 10);    delay(500);  }  // Ride the Rainbow Road ----------------------------------------------------------------------------------------  for (int i = 0; i < LED_COUNT * 10; i++)  {    rainbow(i);    delay(10);  // Delay between rainbow slides  }  // Indigo cylon---------------------------------------------------------------------------------------------------  // Do a cylon (larson scanner) cycle 10 times  for (int i = 0; i < 10; i++)  {    // cylon function: first param is color, second is time (in ms) between cycles    cylon(MIDNIGHTBLUE, 8);  // Indigo cylon eye!  }  // A light shower of spring green rain----------------------------------------------------------------------------  // This will run the cascade from top->bottom 20 times  for (int i = 0; i < 5; i++)  {    // First parameter is the color, second is direction, third is ms between falls    cascade(RED, TOP_DOWN, 5);  } } // Cascades a single direction. One time. void arjan(unsigned long color1, unsigned long color2, unsigned long color3, byte direction, byte wait  ) {  unsigned long color;  if (tel == 1)  {    color = color1;  }  if (tel == 2)  {    color = color2;  }  if (tel == 3)  {    color = color3;  }  tel++;  if (tel > 3)  {    tel = 1;  }  if (direction == TOP_DOWN)  {    for (int i = 0; i < LED_COUNT; i++)    {      // clearLEDs();  // Turn off all LEDs      leds.setPixelColor(i, color);  // Set just this one      leds.show();      delay(wait);    }  }  else  {    for (int i = LED_COUNT - 1; i >= 0; i--)    {      // clearLEDs();      leds.setPixelColor(i, color1);      leds.show();      delay(wait);    }  } } void looplichtRGB(byte wait) {  for (int i = LED_COUNT - 1; i >= 0; i--)  {    // clearLEDs();    leds.setPixelColor(i, led_color[i]);    leds.show();    delay(wait);  } } // Implements a little larson "cylon" sanner. // This'll run one full cycle, down one way and back the other void cylon(unsigned long color, byte wait) {  // weight determines how much lighter the outer "eye" colors are  const byte weight = 50;  // It'll be easier to decrement each of these colors individually  // so we'll split them out of the 24-bit color value  byte red = (color & 0xFF0000) >> 16;  byte green = (color & 0x00FF00) >> 8;  byte blue = (color & 0x0000FF);  // Start at closest LED, and move to the outside  for (int i = 0; i <= LED_COUNT - 1; i++)  {    clearLEDs();    leds.setPixelColor(i, red, green, blue);  // Set the bright middle eye    // Now set two eyes to each side to get progressively dimmer    for (int j = 1; j < 5; j++)    {      if (i - j >= 0)        leds.setPixelColor(i - j, red / (weight * j), green / (weight * j), blue / (weight * j));      if (i - j <= LED_COUNT)        leds.setPixelColor(i + j, red / (weight * j), green / (weight * j), blue / (weight * j));    }    leds.show();  // Turn the LEDs on    delay(wait);  // Delay for visibility  }  // Now we go back to where we came. Do the same thing.  for (int i = LED_COUNT - 4; i >= 1; i--)  {    clearLEDs();    leds.setPixelColor(i, red, green, blue);    for (int j = 1; j < 5; j++)    {      if (i - j >= 0)        leds.setPixelColor(i - j, red / (weight * j), green / (weight * j), blue / (weight * j));      if (i - j <= LED_COUNT)        leds.setPixelColor(i + j, red / (weight * j), green / (weight * j), blue / (weight * j));    }    leds.show();    delay(wait);  } } // Cascades a single direction. One time. void cascade(unsigned long color, byte direction, byte wait) {  if (direction == TOP_DOWN)  {    for (int i = 0; i < LED_COUNT; i++)    {      clearLEDs();  // Turn off all LEDs      leds.setPixelColor(i, color);  // Set just this one      leds.show();      delay(wait);    }  }  else  {    for (int i = LED_COUNT - 1; i >= 0; i--)    {      clearLEDs();      leds.setPixelColor(i, color);      leds.show();      delay(wait);    }  } } // Sets all LEDs to off, but DOES NOT update the display; // call leds.show() to actually turn them off after this. void clearLEDs() {  for (int i = 0; i < LED_COUNT; i++)  {    leds.setPixelColor(i, 0);  } } // Prints a rainbow on the ENTIRE LED strip. //  The rainbow begins at a specified position. // ROY G BIV! void rainbow(byte startPosition) {  // Need to scale our rainbow. We want a variety of colors, even if there  // are just 10 or so pixels.  int rainbowScale = 192 / LED_COUNT;  // Next we setup each pixel with the right color  for (int i = 0; i < LED_COUNT; i++)  {    // There are 192 total colors we can get out of the rainbowOrder function.    // It'll return a color between red->orange->green->...->violet for 0-191.    leds.setPixelColor(i, rainbowOrder((rainbowScale * (i + startPosition)) % 192));  }  // Finally, actually turn the LEDs on:  leds.show(); } // Input a value 0 to 191 to get a color value. // The colors are a transition red->yellow->green->aqua->blue->fuchsia->red... //  Adapted from Wheel function in the Adafruit_NeoPixel library example sketch uint32_t rainbowOrder(byte position) {  // 6 total zones of color change:  if (position < 31)  // Red -> Yellow (Red = FF, blue = 0, green goes 00-FF)  {    return leds.Color(0xFF, position * 8, 0);  }  else if (position < 63)  // Yellow -> Green (Green = FF, blue = 0, red goes FF->00)  {    position -= 31;    return leds.Color(0xFF - position * 8, 0xFF, 0);  }  else if (position < 95)  // Green->Aqua (Green = FF, red = 0, blue goes 00->FF)  {    position -= 63;    return leds.Color(0, 0xFF, position * 8);  }  else if (position < 127)  // Aqua->Blue (Blue = FF, red = 0, green goes FF->00)  {    position -= 95;    return leds.Color(0, 0xFF - position * 8, 0xFF);  }  else if (position < 159)  // Blue->Fuchsia (Blue = FF, green = 0, red goes 00->FF)  {    position -= 127;    return leds.Color(position * 8, 0, 0xFF);  }  else  //160 <position< 191   Fuchsia->Red (Red = FF, green = 0, blue goes FF->00)  {    position -= 159;    return leds.Color(0xFF, 0x00, 0xFF - position * 8);  } }