#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#define MATRIX_WIDTH 7
#define MATRIX_HEIGHT 12
#define PIN 3
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(MATRIX_WIDTH, MATRIX_HEIGHT, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_ZIGZAG,
NEO_GRB + NEO_KHZ800);
const uint16_t colors[] = {
matrix.Color(0, 0, 255), matrix.Color(255, 0, 0)
};
int x = matrix.width();
const char* text = "STACKER";
int strobeIndex = 0;
// State variable using integers
int currentState = 0; // 0 for STROBE, 1 for SCROLL
// Timing variables
unsigned long previousMillis = 0;
const long strobeInterval = 300; // Time between strobe flashes
const long scrollInterval = 100; // Time between scroll updates
unsigned long strobeTiming = 0; // To control strobe effect timing
bool isCharacterVisible = false; // Track visibility of the character
void setup() {
Serial.begin(115200);
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(255);
}
void loop() {
unsigned long currentMillis = millis();
switch (currentState) {
case 0: // STROBE
if (currentMillis - previousMillis >= strobeInterval) {
previousMillis = currentMillis; // Update the last time
strobe();
}
break;
case 1: // SCROLL
if (currentMillis - previousMillis >= scrollInterval) {
previousMillis = currentMillis; // Update the last time
scroll();
}
break;
}
}
void scroll() {
matrix.fillScreen(0); // Turn off all the LEDs
matrix.setTextColor(colors[0]); // Set text color
matrix.setCursor(x, 2);
matrix.print(text);
x--; // Move left
// Reset position if the text has completely scrolled off the screen
if (x < -56) {
x = matrix.width();
currentState = 0;
}
matrix.show();
}
void strobe() {
int textLength = strlen(text);
if (strobeIndex < textLength) {
unsigned long currentMillis = millis();
if (currentMillis - strobeTiming >= strobeInterval / 2) { // Flash every half of the interval
strobeTiming = currentMillis; // Update the last time
if (isCharacterVisible) {
matrix.fillScreen(0); // Clear the matrix
} else {
matrix.fillScreen(0); // Clear the matrix
matrix.setTextColor(colors[1]); // Set text color
// Display the current character
matrix.setCursor(1, 2); // Fixed position
matrix.print(text[strobeIndex]);
}
matrix.show(); // Update display
isCharacterVisible = !isCharacterVisible; // Toggle visibility
if (!isCharacterVisible) { // Move to the next character if the character was shown
strobeIndex++;
if (strobeIndex >= textLength) {
strobeIndex = 0; // Reset index after displaying all characters
currentState = 1; // Switch to scrolling
}
}
}
}
}