#include <Adafruit_GFX.h>
#include <Adafruit_NeoMatrix.h>
#include <Adafruit_NeoPixel.h>
#define PIN 10
Adafruit_NeoMatrix matrix = Adafruit_NeoMatrix(
32, 8, PIN,
NEO_MATRIX_TOP + NEO_MATRIX_LEFT +
NEO_MATRIX_ROWS + NEO_MATRIX_PROGRESSIVE,
NEO_GRB + NEO_KHZ800);
uint8_t mode = 0;
uint32_t lastSwitch = 0;
uint16_t frame = 0;
// =========================
// FAST COLOR WHEEL
// =========================
uint16_t colorWheel(byte pos) {
pos = 255 - pos;
if (pos < 85) {
return matrix.Color(255 - pos * 3, 0, pos * 3);
}
if (pos < 170) {
pos -= 85;
return matrix.Color(0, pos * 3, 255 - pos * 3);
}
pos -= 170;
return matrix.Color(pos * 3, 255 - pos * 3, 0);
}
void setup() {
matrix.begin();
matrix.setBrightness(70);
matrix.setTextWrap(false);
matrix.fillScreen(0);
matrix.show();
}
void loop() {
// Change mode every 6 seconds
if (millis() - lastSwitch > 6000) {
mode = (mode + 1) % 5;
lastSwitch = millis();
frame = 0;
matrix.fillScreen(0);
}
switch (mode) {
// =================================
// MODE 0 : RAINBOW STRIPES
// =================================
case 0:
for (int x = 0; x < 32; x++) {
uint16_t c = colorWheel((x * 8 + frame) & 255);
for (int y = 0; y < 8; y++) {
matrix.drawPixel(x, y, c);
}
}
break;
// =================================
// MODE 1 : ONE COLOR GRID
// =================================
case 1:
matrix.fillScreen(0);
for (int x = 0; x < 32; x += 2) {
for (int y = 0; y < 8; y++) {
matrix.drawPixel(x, y, matrix.Color(0, 255, 0));
}
}
for (int y = 0; y < 8; y += 2) {
for (int x = 0; x < 32; x++) {
matrix.drawPixel(x, y, matrix.Color(0, 255, 0));
}
}
break;
// =================================
// MODE 2 : EMOJI SMILEY
// =================================
case 2:
matrix.fillScreen(0);
// Face
for (int x = 10; x < 22; x++) {
for (int y = 1; y < 7; y++) {
matrix.drawPixel(x, y, matrix.Color(255, 200, 0));
}
}
// Eyes
matrix.drawPixel(13, 2, matrix.Color(0, 0, 0));
matrix.drawPixel(18, 2, matrix.Color(0, 0, 0));
// Smile
matrix.drawPixel(13, 5, matrix.Color(255, 0, 0));
matrix.drawPixel(14, 6, matrix.Color(255, 0, 0));
matrix.drawPixel(15, 6, matrix.Color(255, 0, 0));
matrix.drawPixel(16, 6, matrix.Color(255, 0, 0));
matrix.drawPixel(17, 6, matrix.Color(255, 0, 0));
matrix.drawPixel(18, 5, matrix.Color(255, 0, 0));
break;
// =================================
// MODE 3 : SCROLLING AI CENTRE
// =================================
case 3: {
static int textX1 = 32;
matrix.fillScreen(0);
matrix.setTextColor(colorWheel(frame));
matrix.setCursor(textX1, 0);
matrix.print("AI CENTRE");
textX1--;
if (textX1 < -70) {
textX1 = 32;
}
}
break;
// =================================
// MODE 4 : BY ARVIND SCROLL
// =================================
case 4: {
static int textX2 = 32;
matrix.fillScreen(0);
matrix.setTextColor(matrix.Color(0, 255, 255));
matrix.setCursor(textX2, 0);
matrix.print("BY ARVIND");
textX2--;
if (textX2 < -80) {
textX2 = 32;
}
}
break;
}
matrix.show();
frame++;
delay(30);
}Loading
xiao-esp32-c3
xiao-esp32-c3
https://wokwi.com/projects/463067894155722753