arduino init and made matrix blue
This commit is contained in:
17
main.ino
17
main.ino
@@ -1,17 +0,0 @@
|
||||
#include <FastLED.h>
|
||||
|
||||
#define NUM_LEDS 512
|
||||
#define DATA_PIN 4
|
||||
|
||||
CRGB leds[NUM_LEDS];
|
||||
|
||||
void setup() {
|
||||
FastLED.addLeds<WS2812, DATA_PIN, GRB>(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
|
||||
}
|
60
main/main.ino
Normal file
60
main/main.ino
Normal file
@@ -0,0 +1,60 @@
|
||||
#include <FastLED.h>
|
||||
#include <Adafruit_GFX.h>
|
||||
#include <Fonts/FreeSerif9pt7b.h> // 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<LED_TYPE, DATA_PIN, COLOR_ORDER>(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;
|
||||
}
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user