#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#define PIN 6 // Connect your matrix data pin to Arduino digital pin 6
// Configure a 32x8 NeoPixel Matrix
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(32, 8, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_COLUMNS + NEO_MATRIX_PROGRESSIVE, // ✅ fixed typo
NEO_GRB + NEO_KHZ800);
// Timing configurations (in milliseconds)
const unsigned long PHASE_1_DURATION = 15000; // 15 seconds
const unsigned long PHASE_2_DURATION = 8000; // 8 seconds
const unsigned long TOTAL_CYCLE_TIME = PHASE_1_DURATION + PHASE_2_DURATION;
// Animation Variables
int textX = 32; // Start text just off the right edge of the 32-column display
unsigned long lastScrollTime = 0;
const int scrollSpeed = 60; // Lower numbers = faster scrolling text
uint16_t randomColor;
uint16_t whiteColor = matrix.Color(255, 255, 255); // Pure white for Phase 2
int currentPhase = 1;
unsigned long phaseStartTime = 0;
void setup() {
matrix.begin();
matrix.setTextWrap(false);
matrix.setBrightness(40); // Moderate brightness
// Seed random generator and pick the initial random color
randomSeed(analogRead(0));
randomColor = matrix.Color(random(50, 256), random(50, 256), random(50, 256));
phaseStartTime = millis();
}
void loop() {
unsigned long currentTime = millis();
unsigned long elapsedInPhase = currentTime - phaseStartTime;
// --- STATE MACHINE LOGIC ---
// Phase 1: AI CENTRE NANDURBAR (Random Color) - 15 Seconds
if (currentPhase == 1) {
if (elapsedInPhase >= PHASE_1_DURATION) {
currentPhase = 2;
phaseStartTime = currentTime;
matrix.fillScreen(0);
textX = 32;
} else {
scrollText("AI CENTRE NANDURBAR", randomColor);
}
}
// Phase 2: CODE BY ARVIND (White Color) - 8 Seconds
else if (currentPhase == 2) {
if (elapsedInPhase >= PHASE_2_DURATION) {
currentPhase = 1;
phaseStartTime = currentTime;
matrix.fillScreen(0);
textX = 32;
randomColor = matrix.Color(random(50, 256), random(50, 256), random(50, 256));
} else {
scrollText("CODE BY ARVIND", whiteColor);
}
}
}
// --- HELPER FUNCTION TO HANDLE SMOOTH SCROLLING ---
void scrollText(String text, uint16_t textColor) {
if (millis() - lastScrollTime > scrollSpeed) {
lastScrollTime = millis();
matrix.fillScreen(0);
matrix.setCursor(textX, 0);
matrix.setTextColor(textColor);
matrix.print(text);
matrix.show();
textX--; // Shift text one pixel left
// More accurate text width calculation
int16_t x1, y1;
uint16_t w, h;
matrix.getTextBounds(text, textX, 0, &x1, &y1, &w, &h);
if (textX < -w) {
textX = 32;
}
}
}