Advertisement
Guest User

Untitled

a guest
Jan 8th, 2021
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.34 KB | None | 0 0
  1. // Main File for design sketches for my DIY VW symbol
  2. // Bits of sketch taken from Chemdoc77 and others--
  3.  
  4. #include "FastLED.h"
  5. #define NUM_LEDS 50
  6. #define DATA_PIN 3
  7. #define CHIPSET WS2812B
  8. #define BRIGHTNESS 50
  9. #define COLOR_ORDER GRB
  10. #define UPDATES_PER_SECOND 100
  11.  
  12.  
  13. CRGB rawleds[NUM_LEDS];
  14. CRGBSet leds(rawleds, NUM_LEDS);
  15. CRGBSet leds1(leds(0, 24));
  16. CRGBSet leds2(leds(25, 50));
  17.  
  18.  
  19. struct CRGB * ledarray[] = {leds1, leds2}; // An array of the CRGBSet arrays
  20.  
  21. uint8_t sizearray[] = {25, 25}; // size of the above arrays
  22.  
  23. CRGBPalette16 currentPalette;
  24. TBlendType currentBlending;
  25.  
  26. extern CRGBPalette16 myRedWhiteBluePalette;
  27. extern const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM;
  28.  
  29. void setup() {
  30. delay( 3000 ); // power-up safety delay
  31. FastLED.addLeds<WS2812B, DATA_PIN, GRB>(rawleds, NUM_LEDS).setCorrection( TypicalLEDStrip );
  32. FastLED.setBrightness( BRIGHTNESS );
  33.  
  34. FastLED.setMaxPowerInVoltsAndMilliamps(5, 1500);
  35. set_max_power_indicator_LED(13);
  36.  
  37. currentPalette = myRedWhiteBluePalette_p;
  38. currentBlending = LINEARBLEND;
  39.  
  40. }
  41.  
  42.  
  43.  
  44.  
  45.  
  46. void loop() {
  47.  
  48.  
  49. // fills the whole array
  50. arrayfill(CRGB::White, 700);
  51. arrayfill(CRGB::Blue, 700);
  52.  
  53. //Circle around outside, heartbeat on inside
  54. heartbeat();
  55.  
  56. // Fills one dot at a time
  57. colorwipe_dot(0, CRGB::White, 200);
  58. colorwipe_dot(1, CRGB::Blue, 200);
  59. fill_solid(leds, NUM_LEDS - 1, CRGB::Black);
  60. //red, white, and blue
  61. static uint8_t startIndex = 0;
  62. startIndex = startIndex + 1; /* motion speed */
  63.  
  64. FillLEDsFromPaletteColors( startIndex);
  65.  
  66. FastLED.show();
  67. FastLED.delay(1000 / UPDATES_PER_SECOND);
  68. }
  69. //================ New Functions =====================
  70.  
  71. void colorwipe_dot(uint8_t y, CRGB color, uint32_t wait) { //Note: y is ledarray number
  72. for (uint8_t dot = 0; dot < sizearray[y]; dot++) {
  73. ledarray[y][dot] = color;
  74. FastLED.delay(wait);
  75. ledarray[y][dot] = CRGB::White;
  76. }
  77. }
  78. void arrayfill(CRGB color, uint16_t wait) {
  79.  
  80. for (uint8_t x = 0; x < 2; x++) {
  81. fill_solid(ledarray[x], sizearray[x], color);
  82. FastLED.show();
  83. delay(wait);
  84. fill_solid( ledarray[x], sizearray[x], CRGB::Black);
  85. FastLED.show();
  86.  
  87. }
  88. }
  89.  
  90. void heartbeat() {
  91. for (byte i = 0; i < 5; i++) {
  92. static uint8_t hue;
  93. for (int i = 0; i < NUM_LEDS / 2; i++) {
  94. // fade everything out
  95. leds.fadeToBlackBy(40);
  96.  
  97. // let's set an led value
  98. leds[i] = CRGB::Blue;
  99.  
  100. // now, let's first 20 leds to the top 20 leds,
  101. leds(NUM_LEDS / 2, NUM_LEDS - 1) = leds(NUM_LEDS / 2 - 1 , NUM_LEDS - 1);
  102. FastLED.delay(33);
  103. }
  104. }
  105. }
  106. void FillLEDsFromPaletteColors( uint8_t colorIndex)
  107. {
  108. uint8_t brightness = 255;
  109. for (byte i = 0; i < 5; i++) {
  110. for ( int i = 0; i < NUM_LEDS; i++) {
  111. leds[i] = ColorFromPalette( myRedWhiteBluePalette_p, colorIndex, BRIGHTNESS, currentBlending);
  112. colorIndex += 3;
  113. FastLED.delay(20);
  114. }
  115. }
  116. }
  117.  
  118.  
  119. const TProgmemPalette16 myRedWhiteBluePalette_p PROGMEM =
  120. {
  121. CRGB::Red,
  122. CRGB::Yellow, // 'white' is too bright compared to red and blue
  123. CRGB::Red,
  124. CRGB::Yellow,
  125.  
  126. CRGB::Red,
  127. CRGB::Yellow, // 'white' is too bright compared to red and blue
  128. CRGB::Red,
  129. CRGB::Yellow,
  130.  
  131. CRGB::Red,
  132. CRGB::Red,
  133. CRGB::Yellow,
  134. CRGB::Red,
  135. CRGB::Yellow,
  136. CRGB::Yellow,
  137. CRGB::Red,
  138. CRGB::Yellow
  139. };
  140.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement