Advertisement
PrintService3D

Circuit LED 1

Oct 7th, 2020
102
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.89 KB | None | 0 0
  1. /*
  2.   ****************************************************************
  3.    fastLED_Cylon.ino
  4.  
  5.    Example of defining a CRGB color using Hex,
  6.    and passing that to a function.
  7.  
  8.    Modified the code by Marc Miller, Feb 2017
  9.  ****************************************************************
  10. */
  11.  
  12.  
  13. #include "FastLED.h"
  14. #define DATA_PIN    13
  15. #define LED_TYPE    WS2812B
  16. #define COLOR_ORDER RGB
  17. #define NUM_LEDS   15
  18.  
  19. //#define BRIGHTNESS  127
  20.  
  21. CRGB leds[NUM_LEDS];
  22. uint8_t random8();
  23.  
  24. #define MGPu CRGB(random8(),255,255) // Mardi Gras Purple
  25. #define MGGr CRGB(0, 255, 0) // Mardi Gras Green
  26. #define MGGo CRGB(0, 0, 255) // Mardi Gras Gold
  27. #define MGGa CRGB(255, 255, 200) // Mardi Gras Gold
  28.  
  29.  
  30. //---------------------------------------------------------------
  31. void setup() {
  32.   //Serial.begin(115200);   // Allows serial monitor output (check baud rate)
  33.   //FastLED.show();
  34.   FastLED.addLeds<LED_TYPE, DATA_PIN, COLOR_ORDER>(leds, NUM_LEDS).setCorrection(TypicalLEDStrip);
  35.   //FastLED.setBrightness(BRIGHTNESS);
  36. }
  37.  
  38.  
  39. //---------------------------------------------------------------
  40. void loop() {
  41.   Strobe(0xff, 0xff, 0xff, 10, 0, 0);
  42.   delay(100);
  43.   //cylon(MGPu);  
  44.   //cylon(MGGr);  
  45.   //cylon(MGGo);  
  46.   cylon(MGGa);  
  47.   //Blinker (MGGr);
  48.  
  49.   exit(1);
  50. }
  51.  
  52.  
  53. // ========================== Strobe ==========================
  54.  
  55. void Strobe(byte red, byte green, byte blue, int StrobeCount, int FlashDelay, int EndPause){
  56.   FastLED.setBrightness(200);
  57.   for(int j = 0; j < StrobeCount; j++) {
  58.     setAll(red,green,blue);
  59.     showStrip();
  60.     delay(random(20, 55));
  61.     setAll(0,0,0);
  62.     showStrip();
  63.     delay(random(20, 55));
  64.   }
  65.  
  66.  //delay(EndPause);
  67. }
  68. void showStrip() {
  69.  #ifdef ADAFRUIT_NEOPIXEL_H
  70.    // NeoPixel
  71.    strip.show();
  72.  #endif
  73.  #ifndef ADAFRUIT_NEOPIXEL_H
  74.    // FastLED
  75.    FastLED.show();
  76.  #endif
  77. }
  78.  
  79. void setPixel(int Pixel, byte red, byte green, byte blue) {
  80.  #ifdef ADAFRUIT_NEOPIXEL_H
  81.    // NeoPixel
  82.    strip.setPixelColor(Pixel, strip.Color(red, green, blue));
  83.  #endif
  84.  #ifndef ADAFRUIT_NEOPIXEL_H
  85.    // FastLED
  86.    leds[Pixel].r = red;
  87.    leds[Pixel].g = green;
  88.    leds[Pixel].b = blue;
  89.  #endif
  90. }
  91.  
  92. void setAll(byte red, byte green, byte blue) {
  93.   for(int i = 0; i < NUM_LEDS; i++ ) {
  94.     setPixel(i, red, green, blue);
  95.   }
  96.   showStrip();
  97. }
  98.  
  99.  
  100. // ========================== Lauflicht ==========================
  101. void cylon(CRGB streakcolor) {FastLED.setBrightness(127);
  102.   // Forward
  103.   for (int i = 0; i < NUM_LEDS; i++) {
  104.     leds[i] = streakcolor;
  105.     FastLED.show();
  106.     fadeall();
  107.     delay(40);
  108.   }
  109.   // Reverse
  110.   for (int i = (NUM_LEDS) - 1; i >= 0; i--) {FastLED.setBrightness(180);
  111.     leds[i] = streakcolor;
  112.     FastLED.show();
  113. //    fadeall();
  114.     delay(20);
  115.   }
  116. }
  117.  
  118.  
  119. // ========================== fadeall ==========================
  120. void fadeall()  {
  121.   for (int i = 0; i < NUM_LEDS; i++) {
  122.     leds[i].nscale8(150);
  123.   }
  124. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement