Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- ****************************************************************
- fastLED_Cylon.ino
- Example of defining a CRGB color using Hex,
- and passing that to a function.
- Modified the code by Marc Miller, Feb 2017
- ****************************************************************
- */
- #include "FastLED.h"
- #define DATA_PIN 13
- #define LED_TYPE WS2812B
- #define COLOR_ORDER RGB
- #define NUM_LEDS 15
- //#define BRIGHTNESS 127
- CRGB leds[NUM_LEDS];
- uint8_t random8();
- #define MGPu CRGB(random8(),255,255) // Mardi Gras Purple
- #define MGGr CRGB(0, 255, 0) // Mardi Gras Green
- #define MGGo CRGB(0, 0, 255) // Mardi Gras Gold
- #define MGGa CRGB(255, 255, 200) // Mardi Gras Gold
- //---------------------------------------------------------------
- void setup() {
- //Serial.begin(115200); // Allows serial monitor output (check baud rate)
- //FastLED.show();
- FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
- //FastLED.setBrightness(BRIGHTNESS);
- }
- //---------------------------------------------------------------
- void loop() {
- Strobe(0xff, 0xff, 0xff, 10, 0, 0);
- delay(100);
- //cylon(MGPu);
- //cylon(MGGr);
- //cylon(MGGo);
- cylon(MGGa);
- //Blinker (MGGr);
- exit(1);
- }
- // ========================== Strobe ==========================
- void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){
- FastLED.setBrightness(200);
- for(int j = 0; j < StrobeCount; j++) {
- setAll(red,green,blue);
- showStrip();
- delay(random(20, 55));
- setAll(0,0,0);
- showStrip();
- delay(random(20, 55));
- }
- //delay(EndPause);
- }
- void showStrip() {
- #ifdef ADAFRUIT_NEOPIXEL_H
- // NeoPixel
- strip.show();
- #endif
- #ifndef ADAFRUIT_NEOPIXEL_H
- // FastLED
- FastLED.show();
- #endif
- }
- void setPixel(int Pixel, byte red, byte green, byte blue) {
- #ifdef ADAFRUIT_NEOPIXEL_H
- // NeoPixel
- strip.setPixelColor(Pixel, strip.Color(red, green, blue));
- #endif
- #ifndef ADAFRUIT_NEOPIXEL_H
- // FastLED
- leds[Pixel].r = red;
- leds[Pixel].g = green;
- leds[Pixel].b = blue;
- #endif
- }
- void setAll(byte red, byte green, byte blue) {
- for(int i = 0; i < NUM_LEDS; i++ ) {
- setPixel(i, red, green, blue);
- }
- showStrip();
- }
- // ========================== Lauflicht ==========================
- void cylon(CRGB streakcolor) {FastLED.setBrightness(127);
- // Forward
- for (int i = 0; i < NUM_LEDS; i++) {
- leds[i] = streakcolor;
- FastLED.show();
- fadeall();
- delay(40);
- }
- // Reverse
- for (int i = (NUM_LEDS) - 1; i >= 0; i--) {FastLED.setBrightness(180);
- leds[i] = streakcolor;
- FastLED.show();
- // fadeall();
- delay(20);
- }
- }
- // ========================== fadeall ==========================
- void fadeall() {
- for (int i = 0; i < NUM_LEDS; i++) {
- leds[i].nscale8(150);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement