Advertisement
Guest User

Reddit Question for FastLED

a guest
Feb 15th, 2025
44
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. // Define LED pin
  4. #define LED_DATA_PIN 2 // PB2 (Physical Pin 6) // PD5 (Pin 25) for LED data
  5. #define NUM_LEDS 1 // Single addressable LED
  6.  
  7. CRGB leds[NUM_LEDS];
  8.  
  9. const uint8_t colors[][3] = {
  10. {255, 0, 0}, // Red
  11. {0, 255, 0}, // Green
  12. {0, 0, 255}, // Blue
  13. {255, 255, 0}, // Yellow
  14. {128, 0, 128}, // Purple
  15. {0, 255, 255}, // Cyan
  16. {255, 255, 255} // White
  17. };
  18. const uint8_t numColors = sizeof(colors) / sizeof(colors[0]);
  19.  
  20. void setup() {
  21. // Configure LED data pin as output
  22. PORTB.DIRSET = (1 << LED_DATA_PIN); // Ensure PB2 is set as output
  23. FastPin<LED_DATA_PIN>::setOutput();
  24. FastLED.addLeds<WS2812, LED_DATA_PIN, GRB>(leds, NUM_LEDS);
  25. FastLED.setBrightness(20); // Set brightness to 20% (51 out of 255)
  26. }
  27.  
  28. void loop() {
  29. // Cycle through all colors for the first LED
  30. for (int i = 0; i < numColors; i++) {
  31. leds[0] = CRGB(colors[i][0], colors[i][1], colors[i][2]);
  32. FastLED.show();
  33. delay(500);
  34. }
  35. }
  36.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement