Remote-controlled RGB mood light
Warm, cool, rainbow or breathing: cycle lighting moods from your sofa.
Shop by category
Shop all componentsBuild a set of loading animations, a spinner, a progress bar and moving dots, and cycle between them. Animation is nothing but a frame counter. Each pass through loop() increases frame by one, and every shape on screen is drawn from that number, the spinner's angle, the bar's width, which dot is currently large. Because the counter wraps with %, the motion repeats forever without any special handling. Keep the frame delay near 40 ms and you get roughly 25 frames per second, which is where movement stops looking like stepping.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin.
Every part for this build comes in the Geekobot Titan Kit box, a Geekobot exclusive, together with the parts for all 120 projects, from a first blinking LED to a smart fan and a reaction game. The wiring below is the kit's own wiring.
Tick anything you already have and the total updates.
ESP32 DevKit V1 (38-pin): the brain of every Titan Kit project, with Wi-Fi and Bluetooth
Male-to-female and female-to-female leads for the modules
ESP32 expansion board from the kit: every GPIO has its own S, V, G header
Follow the colours: red is power, dark grey is ground, blue is a signal.
titan_kit_040_oled_animated_loading_scre.inoVerify & upload in Electrolark#include <Wire.h>
#include <Adafruit_GFX.h>
#include <Adafruit_SSD1306.h>
#define SCREEN_WIDTH 128
#define SCREEN_HEIGHT 64
Adafruit_SSD1306 display(SCREEN_WIDTH, SCREEN_HEIGHT, &Wire, -1);
int button = 13;
int style = 0;
int frame = 0;
void spinner()
{
int cx = 64;
int cy = 30;
for (int i = 0; i < 8; i++)
{
float angle = (i * 45 - 90) * PI / 180.0;
int x = cx + cos(angle) * 16;
int y = cy + sin(angle) * 16;
// The dot nearest the current frame is largest
int distance = (i - (frame / 4) % 8 + 8) % 8;
int size = 4 - distance / 2;
if (size > 0)
{
display.fillCircle(x, y, size, SSD1306_WHITE);
}
}
}
void progressBar()
{
int x = 14;
int y = 26;
int w = 100;
int h = 12;
display.drawRect(x, y, w, h, SSD1306_WHITE);
int percent = frame % 101;
int fill = map(percent, 0, 100, 0, w - 4);
display.fillRect(x + 2, y + 2, fill, h - 4, SSD1306_WHITE);
display.setTextSize(1);
display.setCursor(56, 44);
display.print(percent);
display.print("%");
}
void bouncingDots()
{
int active = (frame / 6) % 4;
for (int i = 0; i < 4; i++)
{
int x = 40 + i * 16;
int y = 30;
if (i == active)
{
display.fillCircle(x, y - 6, 5, SSD1306_WHITE);
}
else
{
display.fillCircle(x, y, 3, SSD1306_WHITE);
}
}
}
void setup()
{
pinMode(button, INPUT_PULLUP);
Serial.begin(9600);
if (!display.begin(SSD1306_SWITCHCAPVCC, 0x3C))
{
Serial.println("OLED not found");
while (true) { }
}
display.setTextColor(SSD1306_WHITE);
}
void loop()
{
if (digitalRead(button) == LOW)
{
style = (style + 1) % 3;
frame = 0;
delay(300);
}
frame = frame + 1;
display.clearDisplay();
display.setTextSize(1);
display.setCursor(0, 0);
display.print("LOADING");
if (style == 0) spinner();
else if (style == 1) progressBar();
else bouncingDots();
display.setCursor(0, 56);
display.print("Style ");
display.print(style + 1);
display.print(" of 3");
display.display();
delay(40);
}
Use a micro-USB data cable (some cables only charge), install the CP210x or CH340 driver if no port appears, pick Tools > Board > ESP32 Dev Module and hold the BOOT button on the board until the upload starts.
The sketch uses INPUT_PULLUP, so one leg goes to the GPIO and the other to GND. Use two legs on opposite sides of the button.
Check SDA on GPIO21 and SCL on GPIO22, power from 3V3, and that the sketch uses address 0x3C (some boards are 0x3D).
Animation is nothing but a frame counter. Each pass through loop() increases frame by one, and every shape on screen is drawn from that number, the spinner's angle, the bar's width, which dot is currently large. Because the counter wraps with %, the motion repeats forever without any special handling. Keep the frame delay near 40 ms and you get roughly 25 frames per second, which is where movement stops looking like stepping.
A ring of dots rotates like a loading spinner. Press the button: a progress bar fills from 0 to 100 and repeats. Press again: four dots bounce in sequence.
Yes. It is project 40 of 120 in the Geekobot Titan Kit, in level 8 (OLED graphics). Every part on the list comes in the kit box, and you can also buy the parts one by one from the list above.
No. Every Titan Kit project is wired on the ESP32 expansion board and the breadboard with jumper wires.
7 parts: ESP32-WROOM-32 38-Pin Development Board, USB Cable, Solderless Breadboard, Dupont Jumper Wires (40 pcs), Tactile Push Button Switch, 0.96" OLED Display 128x64 and ESP32 38-Pin Expansion Board. On this page you can tick the parts you already have and add only the rest to your cart.
It is a intermediate project and takes about 30 minutes. The build on this page has 5 steps.
No. This page has the complete, tested code (titan_kit_040_oled_animated_loading_scre.ino).
About ₹824 for the parts at the prices on this page. Quantity price breaks lower the cost when you build several.
Frame-by-frame animation; Driving every shape from one frame counter; Wrapping motion with the % operator; Choosing a frame rate that looks smooth.
The ESP32 is a 3.3V board: never connect a 5V signal straight to a GPIO pin.
Warm, cool, rainbow or breathing: cycle lighting moods from your sofa.
Press to roll: the pips tumble and slow down before landing on a number.
Wait for the light, hit the button: how many milliseconds can you beat?
A bright 4-digit clock that keeps time through power cuts.
Lessons are free to read. Maker (₹499/month) and Pro add quizzes, worked problems and certificates, paid with your Geekobot account. See plans
Learning project. Check every circuit and the datasheet of each part before you power it up.