Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <FastLED.h>
- // Define matrix dimensions
- #define MATRIX_WIDTH 11
- #define MATRIX_HEIGHT 10
- #define NUM_LEDS (MATRIX_WIDTH * MATRIX_HEIGHT)
- // Data pin connected to the LED strip
- #define DATA_PIN 11
- CRGB leds[NUM_LEDS]; // Array to hold LED data
- void setup() {
- FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
- }
- void loop() {
- // Loop through each pixel on the matrix
- for (int y = 0; y < MATRIX_HEIGHT; y++) {
- for (int x = 0; x < MATRIX_WIDTH; x++) {
- // Calculate the LED index based on coordinates
- int ledIndex = XY(x, y);
- // Toggle LED color between red and black
- if (millis() % 1000 < 500) {
- leds[ledIndex] = CRGB::Red;
- } else {
- leds[ledIndex] = CRGB::Black;
- }
- }
- }
- FastLED.show(); // Update the LEDs
- delay(100); // Small delay for visual effect
- }
- // Helper function to calculate LED index from x, y coordinates
- uint16_t XY(uint8_t x, uint8_t y) {
- return (y * MATRIX_WIDTH) + x;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement