Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- // Define LED pin
- #define LED_DATA_PIN 2 // PB2 (Physical Pin 6) // PD5 (Pin 25) for LED data
- #define NUM_LEDS 1 // Single addressable LED
- CRGB leds[NUM_LEDS];
- const uint8_t colors[][3] = {
- {255, 0, 0}, // Red
- {0, 255, 0}, // Green
- {0, 0, 255}, // Blue
- {255, 255, 0}, // Yellow
- {128, 0, 128}, // Purple
- {0, 255, 255}, // Cyan
- {255, 255, 255} // White
- };
- const uint8_t numColors = sizeof(colors) / sizeof(colors[0]);
- void setup() {
- // Configure LED data pin as output
- PORTB.DIRSET = (1 << LED_DATA_PIN); // Ensure PB2 is set as output
- FastPin<LED_DATA_PIN>::setOutput();
- FastLED.addLeds<WS2812, LED_DATA_PIN, GRB>(leds, NUM_LEDS);
- FastLED.setBrightness(20); // Set brightness to 20% (51 out of 255)
- }
- void loop() {
- // Cycle through all colors for the first LED
- for (int i = 0; i < numColors; i++) {
- leds[0] = CRGB(colors[i][0], colors[i][1], colors[i][2]);
- FastLED.show();
- delay(500);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement