Controls
Handheld meal picker
For when nobody can decide what to eat. Scroll through a list of dishes, or press SELECT and let it choose with a spin.
- Hard
- about 70 min
- ESP32-S3
- 8 parts
- 15 wires
- 102 lines of code
ESP32 packs are built on real parts: the simulator runs Arduino Uno circuits only.
Idea
Three buttons and a screen make a menu, the same pattern as a game console or a microwave. The spin slows down like a wheel, which makes a random choice feel fair.
What you learn
Building a scrolling menu, debouncing buttons, and using random numbers.
How it works
input
UP button
DOWN button
SELECT button
decides
ESP32-S3
output
TFT 1.54 in
Buzzer
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
food-picker.ino
// Handheld meal picker
// Cannot decide what to eat? Scroll the list, or press SELECT to let it choose.
#include <SPI.h>
#include <Adafruit_GFX.h>
#include <Adafruit_ST7789.h>
const int PIN_TFT_SCL = 12;
const int PIN_TFT_SDA = 11;
const int PIN_TFT_RES = 14;
const int PIN_TFT_DC = 13;
const int PIN_TFT_CS = 10;
const int PIN_UP_A = 5;
const int PIN_DOWN_A = 6;
const int PIN_SELECT_A = 7;
const int PIN_BUZZER_POS = 17;
// Your own list. Plain letters only: this font has no accents.
const char* MEALS[] = {"Pho bo", "Bun cha", "Com tam", "Banh mi", "Bun bo Hue", "Mi Quang", "Goi cuon", "Hu tieu", "Com ga", "Banh xeo"};
const int MEAL_COUNT = sizeof(MEALS) / sizeof(MEALS[0]);
Adafruit_ST7789 tft(PIN_TFT_CS, PIN_TFT_DC, PIN_TFT_RES);
int cursor = 0;
bool pressed(int pin) {
if (digitalRead(pin) != LOW) return false;
delay(25); // let the contacts settle
if (digitalRead(pin) != LOW) return false;
while (digitalRead(pin) == LOW) delay(5);
return true;
}
void drawList() {
tft.fillScreen(ST77XX_BLACK);
tft.setTextSize(2);
tft.setTextColor(ST77XX_YELLOW);
tft.setCursor(10, 8);
tft.print("What to eat?");
int first = constrain(cursor - 3, 0, max(0, MEAL_COUNT - 7));
for (int row = 0; row < 7 && first + row < MEAL_COUNT; row++) {
int i = first + row;
int y = 40 + row * 28;
if (i == cursor) tft.fillRect(0, y - 4, 240, 26, 0x02B5);
tft.setTextColor(ST77XX_WHITE);
tft.setCursor(14, y);
tft.print(MEALS[i]);
}
}
void drawPick(const char* meal, bool final) {
tft.fillScreen(final ? 0x0320 : ST77XX_BLACK);
tft.setTextColor(ST77XX_WHITE);
tft.setTextSize(2);
tft.setCursor(10, 60);
tft.print(final ? "Today:" : "...");
tft.setTextSize(3);
tft.setCursor(10, 110);
tft.print(meal);
}
void spin() {
int pick = 0;
// fast at first, then slowing down, like a wheel
for (int wait = 40; wait < 400; wait += wait / 4 + 5) {
pick = random(MEAL_COUNT);
drawPick(MEALS[pick], false);
tone(PIN_BUZZER_POS, 1000, 20);
delay(wait);
}
drawPick(MEALS[pick], true);
tone(PIN_BUZZER_POS, 1320, 120);
delay(160);
tone(PIN_BUZZER_POS, 1760, 250);
cursor = pick;
while (digitalRead(PIN_SELECT_A) == HIGH && digitalRead(PIN_UP_A) == HIGH && digitalRead(PIN_DOWN_A) == HIGH) delay(20);
delay(200);
drawList();
}
void setup() {
pinMode(PIN_UP_A, INPUT_PULLUP);
pinMode(PIN_DOWN_A, INPUT_PULLUP);
pinMode(PIN_SELECT_A, INPUT_PULLUP);
pinMode(PIN_BUZZER_POS, OUTPUT);
randomSeed(esp_random());
SPI.begin(PIN_TFT_SCL, -1, PIN_TFT_SDA, PIN_TFT_CS);
tft.init(240, 240);
tft.setRotation(2);
drawList();
}
void loop() {
if (pressed(PIN_UP_A)) {
cursor = (cursor + MEAL_COUNT - 1) % MEAL_COUNT;
drawList();
}
if (pressed(PIN_DOWN_A)) {
cursor = (cursor + 1) % MEAL_COUNT;
drawList();
}
if (pressed(PIN_SELECT_A)) spin();
delay(10);
}
Libraries
- Adafruit GFX Library: install it from Sketch > Include Library > Manage Libraries.
- Adafruit ST7735 and ST7789 Library: 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”.