slider-luminosite.ino

Arduino Esplora — Board Fiche · File : slider-luminosite.ino · Language : Arduino · Use case : Régler la luminosité de la LED RGB avec le slider latéral

The side slider is a variable resistor read in analog: it directly modulates the RGB LED brightness. A first step into the « tangible » interfaces the Esplora loves.

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.

Wiring

Nothing to wire.

How it works

readSlider returns 0-1023; map scales it to 8 bits for writeRGB, which drives the three channels (D5 red, D10 green, D9 blue). In the Arduino IDE, select « Arduino Esplora »; add the « Esplora » library from the Library Manager to reach the onboard sensors.

Going further

Shift the hue along the travel (red → green → blue) for a color picker.

slider-luminosite.ino

// Slider lateral (0..1023) -> intensite de la LED RGB embarquee.
#include <Esplora.h>

void setup() {
  Serial.begin(9600);
}

void loop() {
  int v = Esplora.readSlider();     // 0..1023
  int intensite = map(v, 0, 1023, 0, 255);
  Esplora.writeRGB(intensite, intensite / 4, 0); // blanc->orange
  Serial.println(intensite);        // retour du curseur sur le moniteur
  delay(20);
}

← Back to the board