
Arduino Quick Start
Environment Setup: Refer to the Arduino IDE Quick Start Tutorial to complete the IDE installation, and install the corresponding board manager and required driver libraries according to the development board you are using.
Required Libraries:
Hardware Used:

G26 (SCL) and G0 (SDA).#include "M5Unified.h"
#include "M5HatMiniJoyC.h"
// MiniJoyC I2C pins
#define MiniJoyC_SDA 0
#define MiniJoyC_SCL 26
M5HatMiniJoyC joyc;
// Wait until MiniJoyC is ready
static void waitMiniJoyCReady() {
while (!joyc.begin(&Wire, MiniJoyC_ADDR, MiniJoyC_SDA, MiniJoyC_SCL, 100000UL)) {
delay(100);
}
}
void setup() {
M5.begin();
waitMiniJoyCReady();
M5.Display.setRotation(0);
M5.Display.setFont(&fonts::FreeMonoBold9pt7b);
M5.Display.fillScreen(BLACK);
}
void loop() {
M5.update();
// Read raw ADC values (0~4095)
int16_t adc_x = joyc.getADCValue(ADC_X);
int16_t adc_y = joyc.getADCValue(ADC_Y);
// Read normalized position (-128~127)
int8_t pos_x = joyc.getPOSValue(POS_X, _8bit);
int8_t pos_y = joyc.getPOSValue(POS_Y, _8bit);
// Display values
M5.Display.fillScreen(BLACK);
M5.Display.setTextColor(WHITE, BLACK);
M5.Display.setCursor(0, 20);
M5.Display.printf("ADC X:%4d", adc_x);
M5.Display.setCursor(0, 50);
M5.Display.printf("ADC Y:%4d", adc_y);
M5.Display.drawLine(0, 80, 135, 80, ORANGE);
M5.Display.setCursor(0, 100);
M5.Display.printf("POS X:%4d", pos_x);
M5.Display.setCursor(0, 130);
M5.Display.printf("POS Y:%4d", pos_y);
M5.Display.drawLine(0, 160, 135, 160, ORANGE);
M5.Display.setCursor(0, 180);
M5.Display.printf("BtnVal: %d", joyc.getButtonStatus());
// Map joystick to RGB888
uint8_t r = constrain(map(-pos_y, -128, 127, 0, 255), 0, 255);
uint8_t g = constrain(map( pos_y, -128, 127, 0, 255), 0, 255);
uint8_t b = constrain(map( pos_x, -128, 127, 0, 255), 0, 255);
// Center dead zone → white
if (abs(pos_x) < 8 && abs(pos_y) < 8) {
r = g = b = 255;
}
// Combine to RGB888 (0xRRGGBB)
uint32_t rgb888 = (r << 16) | (g << 8) | b;
// Set MiniJoyC LED color
joyc.setLEDColor(rgb888);
delay(30);
}