From 8808d8630518300b6151868d20a3cdc9d8932a90 Mon Sep 17 00:00:00 2001 From: Sam Hos Date: Sat, 30 Nov 2024 12:37:13 +0100 Subject: [PATCH] arduino init and made matrix blue --- main.ino | 17 --------------- main/main.ino | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 60 insertions(+), 17 deletions(-) delete mode 100644 main.ino create mode 100644 main/main.ino diff --git a/main.ino b/main.ino deleted file mode 100644 index cae7a03..0000000 --- a/main.ino +++ /dev/null @@ -1,17 +0,0 @@ -#include - -#define NUM_LEDS 512 -#define DATA_PIN 4 - -CRGB leds[NUM_LEDS]; - -void setup() { - FastLED.addLeds(leds, NUM_LEDS); // Use GRB color order - FastLED.setBrightness(50); // Lower brightness to reduce power draw -} - -void loop() { - fill_solid(leds, NUM_LEDS, CRGB::Red); // Set all LEDs to red - FastLED.show(); - delay(500); // Pause for half a second -} diff --git a/main/main.ino b/main/main.ino new file mode 100644 index 0000000..3a73591 --- /dev/null +++ b/main/main.ino @@ -0,0 +1,60 @@ +#include +#include +#include // Optional: Use any font from Adafruit_GFX + +#define DATA_PIN D2 // Data pin for the matrix +#define NUM_LEDS 256 // Total LEDs (8 rows x 32 columns) +#define LED_TYPE WS2812 // LED type +#define COLOR_ORDER GRB // Color order + +CRGB leds[NUM_LEDS]; // Array to store the LED colors +Adafruit_GFX *gfx; // Pointer to the graphics object +int textX = 32; // Starting X position for scrolling text + +void setup() { + FastLED.addLeds(leds, NUM_LEDS); // Set up FastLED + FastLED.setBrightness(50); // Set brightness level (0-255) + + gfx = new Adafruit_GFX(32, 8); // Initialize the graphics object for a 32x8 matrix + + // Initialize the matrix (clear it first) + fill_solid(leds, NUM_LEDS, CRGB::Black); + FastLED.show(); +} + +void loop() { + // Message to scroll + String message = "Hello World! "; + + // Scroll the message across the screen + for (int x = textX; x >= -message.length() * 6; x--) { + // Clear the previous frame + fill_solid(leds, NUM_LEDS, CRGB::Black); + + // Draw the text at the current position (x) + gfx->setCursor(x, 0); + gfx->setTextColor(CRGB::White); // Set text color + gfx->setTextSize(1); // Set text size + gfx->print(message); // Print the message + + // Copy the graphics buffer to the LED array + drawMatrixToLEDs(); + + // Show the updated LEDs + FastLED.show(); + delay(100); // Adjust the speed of the scroll + } + + // Reset the starting point for the scroll after it goes off-screen + textX = 32; +} + +// Function to copy the Adafruit_GFX buffer to the LED array +void drawMatrixToLEDs() { + for (int i = 0; i < 32; i++) { + for (int j = 0; j < 8; j++) { + int pixelColor = gfx->getTextColor(); // Get the color of the pixel (white or black) + leds[j + i * 8] = (pixelColor == CRGB::White) ? CRGB::White : CRGB::Black; + } + } +}