Advertisement
Guest User

matrix_test.ino

a guest
Feb 19th, 2025
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.00 KB | None | 0 0
  1. #include <FastLED.h>
  2.  
  3. // Define matrix dimensions
  4. #define MATRIX_WIDTH 11
  5. #define MATRIX_HEIGHT 10
  6. #define NUM_LEDS (MATRIX_WIDTH * MATRIX_HEIGHT)
  7.  
  8. // Data pin connected to the LED strip
  9. #define DATA_PIN 11
  10.  
  11. CRGB leds[NUM_LEDS]; // Array to hold LED data
  12.  
  13. void setup() {
  14. FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);
  15. }
  16.  
  17. void loop() {
  18. // Loop through each pixel on the matrix
  19. for (int y = 0; y < MATRIX_HEIGHT; y++) {
  20. for (int x = 0; x < MATRIX_WIDTH; x++) {
  21. // Calculate the LED index based on coordinates
  22. int ledIndex = XY(x, y);
  23.  
  24. // Toggle LED color between red and black
  25. if (millis() % 1000 < 500) {
  26. leds[ledIndex] = CRGB::Red;
  27. } else {
  28. leds[ledIndex] = CRGB::Black;
  29. }
  30. }
  31. }
  32. FastLED.show(); // Update the LEDs
  33. delay(100); // Small delay for visual effect
  34. }
  35.  
  36. // Helper function to calculate LED index from x, y coordinates
  37. uint16_t XY(uint8_t x, uint8_t y) {
  38. return (y * MATRIX_WIDTH) + x;
  39. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement