Guest User

Untitled

a guest
Oct 7th, 2025
110
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | Science | 0 0
  1. #include <Arduino.h>
  2. #include <FastLED.h>
  3.  
  4. // --- LED Configuration ---
  5. #define NUM_LEDS 16
  6. #define DATA_PIN 17
  7. #define BRIGHTNESS 64 // Use a moderate brightness for testing (0-255)
  8.  
  9. // --- Global Variables ---
  10. CRGB leds[NUM_LEDS];
  11.  
  12. void setup() {
  13. Serial.begin(115200);
  14. delay(1000); // A small delay to let the serial monitor connect
  15. Serial.println("ESP32-S3 FastLED Standalone Test");
  16. Serial.println("Starting left-to-right sweep...");
  17.  
  18. // Initialize the LED strip
  19. FastLED.addLeds<WS2812, DATA_PIN, GRB>(leds, NUM_LEDS);
  20. FastLED.setBrightness(BRIGHTNESS);
  21.  
  22. // Start with all LEDs off
  23. FastLED.clear();
  24. FastLED.show();
  25. }
  26.  
  27. void loop() {
  28. // --- SWEEP UP (Green to Red) ---
  29. for (int ledsToLight = 0; ledsToLight <= NUM_LEDS; ledsToLight++) {
  30.  
  31. // First, clear all LEDs to black
  32. FastLED.clear();
  33.  
  34. // Then, light up the ones we need for this frame
  35. for (int i = 0; i < ledsToLight; i++) {
  36. // Map the LED index to a hue from Green (96) to Red (0)
  37. uint8_t hue = map(i, 0, NUM_LEDS - 1, 96, 0);
  38. leds[i] = CHSV(hue, 255, 255);
  39. }
  40.  
  41. FastLED.show();
  42. delay(50); // Controls the speed of the sweep
  43.  
  44. }
  45.  
  46. delay(500); // Pause with all LEDs lit red before repeating
  47. }
Advertisement
Add Comment
Please, Sign In to add comment