Controls
Smart knob
A knob with a round screen in the middle and a ring of light round it. Turn to set brightness, press to switch to colour.
- Hard
- about 75 min
- ESP32-S3
- 8 parts
- 15 wires
- 86 lines of code
ESP32 packs are built on real parts: the simulator runs Arduino Uno circuits only.
Idea
The same number is shown three ways at once: as digits, as an arc on the screen and as lit LEDs. Good controls always answer you through more than one sense.
What you learn
Combining an encoder, a screen and LEDs, and one control that changes meaning by mode.
How it works
input
Rotary knob
decides
ESP32-S3
output
Round screen
LED ring
Powered with 5 V through the board's USB-C port.
A reference design. The sketch is compiled with the real ESP32 toolchain, and its pins are checked against the wiring table automatically. It has not yet been built and tested on real parts by us, so wire it on the bench and run the checks before you build it into a case. Real modules vary: follow the labels printed on yours, not their position in the picture.
Parts
0 of 8 ready
No prices here: they change by shop and by week. Buy each part by its name and the note beside it.
You also need
A computer with Arduino IDE 2 installed (free)
3D wiring
One jumper per step, with the USB cable unplugged. Several wires may share 3V3, 5V or GND: the expansion board or breadboard gives each its own pin.
Step 0 of 15
Lay out the parts
Seat the board on its expansion board or breadboard and lay the modules out round it. Nothing is connected yet.
All connections
smart-knob.ino
// Smart knob
// Turn the knob: the round screen shows the value and the ring of light fills
// up with it. Press to switch between brightness and colour.
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_GC9A01A.h>
#include <Adafruit_NeoPixel.h>
const int PIN_KNOB_CLK = 5;
const int PIN_KNOB_DT = 6;
const int PIN_KNOB_SW = 7;
const int PIN_DIAL_SCL = 12;
const int PIN_DIAL_SDA = 11;
const int PIN_DIAL_DC = 13;
const int PIN_DIAL_CS = 10;
const int PIN_DIAL_RES = 14;
const int PIN_RING_DIN = 16;
const int LED_COUNT = 12;
Adafruit_GC9A01A tft(PIN_DIAL_CS, PIN_DIAL_DC, PIN_DIAL_RES);
Adafruit_NeoPixel ring(LED_COUNT, PIN_RING_DIN, NEO_GRB + NEO_KHZ800);
int level = 50; // brightness, 0..100
int hue = 30; // colour, 0..100 round the wheel
bool settingHue = false;
int lastClk = HIGH;
void showRing() {
int lit = map(level, 0, 100, 0, LED_COUNT);
uint32_t colour = ring.gamma32(ring.ColorHSV((uint16_t)(hue * 655)));
for (int i = 0; i < LED_COUNT; i++) ring.setPixelColor(i, i < lit ? colour : 0);
ring.setBrightness(20 + level * 2);
ring.show();
}
void drawDial() {
int value = settingHue ? hue : level;
tft.fillScreen(GC9A01A_BLACK);
// an arc of dots from 135 to 405 degrees, filled up to the value
for (int i = 0; i <= 50; i++) {
float a = (135 + i * 5.4f) * DEG_TO_RAD;
bool on = i * 2 <= value;
tft.fillCircle(120 + cos(a) * 104, 120 + sin(a) * 104, on ? 5 : 2, on ? GC9A01A_CYAN : 0x4208);
}
tft.setTextColor(GC9A01A_WHITE);
tft.setTextSize(6);
tft.setCursor(value < 10 ? 102 : value < 100 ? 84 : 66, 92);
tft.print(value);
tft.setTextSize(2);
tft.setTextColor(GC9A01A_YELLOW);
tft.setCursor(settingHue ? 84 : 60, 160);
tft.print(settingHue ? "COLOUR" : "BRIGHTNESS");
}
void setup() {
pinMode(PIN_KNOB_CLK, INPUT_PULLUP);
pinMode(PIN_KNOB_DT, INPUT_PULLUP);
pinMode(PIN_KNOB_SW, INPUT_PULLUP);
ring.begin();
SPI.begin(PIN_DIAL_SCL, -1, PIN_DIAL_SDA, PIN_DIAL_CS);
tft.begin();
lastClk = digitalRead(PIN_KNOB_CLK);
showRing();
drawDial();
}
void loop() {
int clk = digitalRead(PIN_KNOB_CLK);
if (clk != lastClk && clk == LOW) {
int change = digitalRead(PIN_KNOB_DT) == HIGH ? 5 : -5;
if (settingHue) hue = (hue + change + 100) % 100;
else level = constrain(level + change, 0, 100);
showRing();
drawDial();
}
lastClk = clk;
if (digitalRead(PIN_KNOB_SW) == LOW) {
delay(30);
while (digitalRead(PIN_KNOB_SW) == LOW) delay(5);
settingHue = !settingHue;
drawDial();
}
delay(1);
}
Libraries
- Adafruit GFX Library: install it from Sketch > Include Library > Manage Libraries.
- Adafruit GC9A01A: install it from Sketch > Include Library > Manage Libraries.
- Adafruit NeoPixel: install it from Sketch > Include Library > Manage Libraries.
Uploading
First time with an ESP32: in Arduino IDE open Boards Manager, search “esp32” and install “esp32 by Espressif Systems”.
- Open the sketch in Arduino IDE.
- Plug the board in with the USB-C cable.
- Tools > Board > ESP32S3 Dev Module, then Tools > Port and choose the board's port.
- Press Upload (the arrow). Wait for “Done uploading”.