177 lines
4.6 KiB
C++
177 lines
4.6 KiB
C++
#include <Wire.h>
|
|
#include <FastLED.h>
|
|
#include <Adafruit_SSD1306.h>
|
|
#include <Adafruit_DotStarMatrix.h>
|
|
#include <Adafruit_DotStar.h>
|
|
#include <SPI.h>
|
|
|
|
// ============ PIN DEFINITIONS (ESP32-S3 Super Mini) ============
|
|
|
|
#define JOY_X_PIN A1 // Example: GP2, adjust to your wiring
|
|
#define JOY_Y_PIN A2 // Example: GP3, adjust to your wiring
|
|
#define JOY_BTN_PIN 3 // Example: GP8, adjust to your wiring
|
|
|
|
#define LOCAL_I2C_SDA 12 // Example: GP9, SDA for OLED/APDS
|
|
#define LOCAL_I2C_SCL 11 // Example: GP10, SCL for OLED/APDS
|
|
|
|
#define NUM_LEDS 16
|
|
#define LED_DATA_PIN 8 // Example: GP11, adjust to your wiring
|
|
|
|
#define DOTSTAR_WIDTH 8
|
|
#define DOTSTAR_HEIGHT 8
|
|
#define DOTSTAR_DATA 10 // Example: GP12, adjust to your wiring
|
|
#define DOTSTAR_CLK 9 // Example: GP13, adjust to your wiring
|
|
|
|
#define ONBOARD_RGB_LED 48 // Onboard WS2812 RGB LED on GP48
|
|
|
|
// ============ DEVICE OBJECTS =============
|
|
|
|
Adafruit_SSD1306 display(128, 64, &Wire, -1);
|
|
CRGB leds[NUM_LEDS];
|
|
|
|
Adafruit_DotStarMatrix dotstar = Adafruit_DotStarMatrix(
|
|
DOTSTAR_WIDTH, DOTSTAR_HEIGHT, DOTSTAR_DATA, DOTSTAR_CLK,
|
|
DS_MATRIX_TOP + DS_MATRIX_LEFT + DS_MATRIX_ROWS + DS_MATRIX_PROGRESSIVE,
|
|
DOTSTAR_BRG
|
|
);
|
|
|
|
// ============ I2C SCAN FUNCTION =========
|
|
|
|
void scanI2CDevices(TwoWire &bus) {
|
|
byte error, address;
|
|
int nDevices = 0;
|
|
Serial.println("Scanning...");
|
|
for (address = 1; address < 127; address++) {
|
|
bus.beginTransmission(address);
|
|
error = bus.endTransmission();
|
|
if (error == 0) {
|
|
Serial.print("I2C device found at address 0x");
|
|
if (address < 16) Serial.print("0");
|
|
Serial.println(address, HEX);
|
|
nDevices++;
|
|
}
|
|
delay(1);
|
|
}
|
|
if (nDevices > 0) {
|
|
Serial.println("done");
|
|
}
|
|
}
|
|
|
|
// ============ ONBOARD RGB LED TEST =========
|
|
|
|
void testOnboardRGB() {
|
|
// Note: Onboard RGB LED is a WS2812 on GP48
|
|
FastLED.addLeds<NEOPIXEL, ONBOARD_RGB_LED>(leds, 1); // Use just 1 LED
|
|
leds[0] = CRGB::Red;
|
|
FastLED.show();
|
|
delay(500);
|
|
leds[0] = CRGB::Blue;
|
|
FastLED.show();
|
|
delay(500);
|
|
leds[0] = CRGB::Green;
|
|
FastLED.show();
|
|
delay(500);
|
|
FastLED.clear();
|
|
FastLED.show();
|
|
FastLED.clear(true); // Clear LED data and reset FastLED for main NeoPixel strip
|
|
}
|
|
|
|
// ============ SYSTEM TEST =========
|
|
|
|
void runSystemTest() {
|
|
|
|
Serial.println("\n===== SYSTEM TEST =====\n");
|
|
|
|
// --- Onboard RGB LED Test ---
|
|
|
|
Serial.println("Testing onboard RGB LED...");
|
|
testOnboardRGB();
|
|
Serial.println("Onboard RGB LED: OK");
|
|
|
|
// --- Joystick Test ---
|
|
|
|
int joyX = analogRead(JOY_X_PIN);
|
|
int joyY = analogRead(JOY_Y_PIN);
|
|
int joyBtn = digitalRead(JOY_BTN_PIN);
|
|
Serial.print("Joystick X: "); Serial.println(joyX);
|
|
Serial.print("Joystick Y: "); Serial.println(joyY);
|
|
Serial.print("Button: "); Serial.println(joyBtn ? "Released" : "Pressed");
|
|
Serial.println("Joystick: OK");
|
|
|
|
// --- I2C Device Scan ---
|
|
|
|
Serial.println("Scanning I2C devices...");
|
|
scanI2CDevices(Wire);
|
|
|
|
// --- OLED Test ---
|
|
|
|
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C)) {
|
|
Serial.println("OLED: FAIL");
|
|
while(1);
|
|
}
|
|
|
|
display.clearDisplay();
|
|
display.setTextSize(1);
|
|
display.setTextColor(SSD1306_WHITE);
|
|
display.setCursor(0,0);
|
|
display.println("SYSTEM TEST");
|
|
display.println("Joystick OK");
|
|
display.println("I2C OK");
|
|
display.println("FastLED OK");
|
|
display.println("DotStar OK");
|
|
display.display();
|
|
Serial.println("OLED: OK");
|
|
|
|
// --- FastLED (NeoPixel) Test ---
|
|
|
|
FastLED.addLeds<NEOPIXEL, LED_DATA_PIN>(leds, NUM_LEDS);
|
|
|
|
for (int i = 0; i < NUM_LEDS; i++) {
|
|
leds[i] = CRGB(0, 255, 0); // Green
|
|
}
|
|
FastLED.show();
|
|
delay(1000);
|
|
FastLED.clear();
|
|
FastLED.show();
|
|
Serial.println("FastLED: OK");
|
|
|
|
// --- DotStar (APA102) Test ---
|
|
|
|
dotstar.begin();
|
|
dotstar.setBrightness(32);
|
|
dotstar.fillScreen(dotstar.Color(255, 0, 0)); // Red
|
|
dotstar.show();
|
|
delay(1000);
|
|
dotstar.fillScreen(0);
|
|
dotstar.show();
|
|
Serial.println("DotStar: OK");
|
|
|
|
Serial.println("===== SYSTEM TEST COMPLETE =====");
|
|
}
|
|
|
|
// ============ SETUP =============
|
|
|
|
void setup() {
|
|
|
|
Serial.begin(115200);
|
|
|
|
while(!Serial) { delay(10); }
|
|
|
|
// Initialize I2C
|
|
Wire.begin(LOCAL_I2C_SDA, LOCAL_I2C_SCL, 100000);
|
|
|
|
// Initialize joystick button
|
|
pinMode(JOY_BTN_PIN, INPUT_PULLUP);
|
|
|
|
// Run system test
|
|
runSystemTest();
|
|
|
|
// Keep the loop empty as recommended for ESP32-S3 Super Mini
|
|
while(true) {}
|
|
}
|
|
|
|
// ============ LOOP =============
|
|
|
|
void loop() {
|
|
// Leave empty to avoid crashes on ESP32-S3 Super Mini
|
|
} |