From cd091037c0a9c56f7433f7e491dbc7557fad9847 Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Sat, 30 Nov 2024 20:09:27 +0100 Subject: [PATCH] reorginasation + matrix test tool --- {main => src/main}/LEDMatrix.cpp | 17 +++++++++++++++++ {main => src/main}/LEDMatrix.h | 4 +++- {main => src/main}/conf.h | 0 {main => src/main}/font.h | 0 {main => src/main}/main.ino | 0 src/matrixTester/matrixTester.ino | 27 +++++++++++++++++++++++++++ 6 files changed, 47 insertions(+), 1 deletion(-) rename {main => src/main}/LEDMatrix.cpp (89%) rename {main => src/main}/LEDMatrix.h (84%) rename {main => src/main}/conf.h (100%) rename {main => src/main}/font.h (100%) rename {main => src/main}/main.ino (100%) create mode 100644 src/matrixTester/matrixTester.ino diff --git a/main/LEDMatrix.cpp b/src/main/LEDMatrix.cpp similarity index 89% rename from main/LEDMatrix.cpp rename to src/main/LEDMatrix.cpp index 8df51f5..8cdb7b5 100644 --- a/main/LEDMatrix.cpp +++ b/src/main/LEDMatrix.cpp @@ -3,6 +3,7 @@ LEDMatrix::LEDMatrix(uint8_t width, uint8_t height, uint16_t numLeds, uint16_t lastVisibleLed, CRGB* leds) : kMatrixWidth(width), kMatrixHeight(height), NUM_LEDS(numLeds), LAST_VISIBLE_LED(lastVisibleLed), leds(leds) { + //the led matrix reference table static const int table[] = { 248, 247, 232, 231, 216, 215, 200, 199, 184, 183, 168, 167, 152, 151, 136, 135, 120, 119, 104, 103, 88, 87, 72, 71, 56, 55, 40, 39, 24, 23, 8, 7, 249, 246, 233, 230, 217, 214, 201, 198, 185, 182, 169, 166, 153, 150, 137, 134, 121, 118, 105, 102, 89, 86, 73, 70, 57, 54, 41, 38, 25, 22, 9, 6, @@ -66,4 +67,20 @@ void LEDMatrix::drawText(const char* text, int x, int y, CRGB color) { y += 8; // Move to the next line } } +} + +void LEDMatrix::setLEDColor(uint16_t index, CRGB color) { + if (index <= LAST_VISIBLE_LED) { + leds[index] = color; + } +} + +void LEDMatrix::setLEDArray(const long ledarray[]) { + for (uint16_t i = 0; i < NUM_LEDS; i++) { + if (ledarray[i] == 255) { + setLEDColor(i, CRGB::White); // Set the color to white for simplicity + } else { + setLEDColor(i, CRGB::Black); // Turn off the LED + } + } } \ No newline at end of file diff --git a/main/LEDMatrix.h b/src/main/LEDMatrix.h similarity index 84% rename from main/LEDMatrix.h rename to src/main/LEDMatrix.h index 6c154af..ace8fdd 100644 --- a/main/LEDMatrix.h +++ b/src/main/LEDMatrix.h @@ -11,6 +11,8 @@ public: void drawPixel(uint8_t x, uint8_t y, CRGB color); void drawChar(char c, int x, int y, CRGB color); void drawText(const char* text, int x, int y, CRGB color); + void setLEDColor(uint16_t index, CRGB color); + void setLEDArray(const long ledarray[]); private: const uint8_t kMatrixWidth; @@ -18,7 +20,7 @@ private: const uint16_t NUM_LEDS; const uint16_t LAST_VISIBLE_LED; const int* XYTable; - CRGB* leds; // Add this line + CRGB* leds; }; #endif // LEDMATRIX_H \ No newline at end of file diff --git a/main/conf.h b/src/main/conf.h similarity index 100% rename from main/conf.h rename to src/main/conf.h diff --git a/main/font.h b/src/main/font.h similarity index 100% rename from main/font.h rename to src/main/font.h diff --git a/main/main.ino b/src/main/main.ino similarity index 100% rename from main/main.ino rename to src/main/main.ino diff --git a/src/matrixTester/matrixTester.ino b/src/matrixTester/matrixTester.ino new file mode 100644 index 0000000..91e86d7 --- /dev/null +++ b/src/matrixTester/matrixTester.ino @@ -0,0 +1,27 @@ +//The only thing this does is light up each LED one by one in red, then clear them all and repeat. + +#include + +#define NUM_LEDS 512 // 8x32 matrix * 2 +#define DATA_PIN D2 // Data pin for WS2812 + +CRGB leds[NUM_LEDS]; // Array of LEDs + +void setup() { + FastLED.addLeds(leds, NUM_LEDS); // Initialize FastLED + FastLED.setBrightness(100); // Set brightness (0-255) +} + +void loop() { + // Clear all LEDs + FastLED.clear(); + + // Enable each LED one by one + for (int i = 0; i < NUM_LEDS; i++) { + leds[i] = CRGB::Red; // Set to a color (e.g., red) + FastLED.show(); // Update the LED matrix + delay(50); // Adjust the speed of the LED lighting (lower = faster) + } + + delay(1000); // Hold the final state for a while before clearing +} \ No newline at end of file