joystick-couleur.ino
The analog joystick (−512 to +512 per axis) directly drives the red and green channels of the onboard RGB LED: a tangible color wheel with zero wiring.
Hardware required
An Arduino Esplora (ATmega32U4, 5 V) with its onboard sensors: joystick, 4 buttons, slider, RGB LED, buzzer, light, temperature, sound and accelerometer. None: everything is onboard.
Wiring
Nothing to wire; handle the board gently, the joystick is fragile.
How it works
readJoystickX/Y return the deviation; map converts it to 8-bit intensities that writeRGB applies to pins D5/D10. In the Arduino IDE, select « Arduino Esplora »; add the « Esplora » library from the Library Manager to reach the onboard sensors.
Going further
Add the blue channel via the slider, or store a favorite color on joystick center press.
joystick-couleur.ino
// Joystick -> melange rouge/vert sur la LED RGB embarquee.
#include <Esplora.h>
void setup() {
Serial.begin(9600);
}
void loop() {
int jx = Esplora.readJoystickX(); // -512..512 (positif = gauche)
int jy = Esplora.readJoystickY();
int rouge = map(-jx, -512, 512, 0, 255);
int vert = map(-jy, -512, 512, 0, 255);
Esplora.writeRGB(rouge, vert, 0);
Serial.print(rouge); Serial.print('\t'); Serial.println(vert);
delay(30);
}