Pick a mood, shape the eyes, and watch them blink on a pixel-exact OLED preview. The code below the controls redraws the same eyes on your board, with no bitmaps to store.
Each step holds a mood for the time you set, then the eyes ease into the next one.
Serial: send 0 to 8 for a mood, r to resume, b to blink. A TTP223 touch pad makes the eyes happy for two seconds.
Everything you change above is turned into a handful of numbers in the generated code, so what you see in the preview is exactly what your board draws. These notes explain what each group of settings does and suggest starting points for popular robot styles.
| Style | Width × Height | Corner radius | Gap | Extras |
|---|---|---|---|---|
| EMO / Cozmo-style desk robot | 36 × 36 | 8 to 10 | 14 | No pupils, breathing bob on |
| Tall pill eyes | 22 × 44 | 11 (half the width) | 20 | Look range up/down 4 or less |
| Wide visor | 50 × 16 | 4 | 8 | Works well on 128×32 bar screens |
| Cute cartoon eyes | 30 × 34 | 14 | 16 | Pupils on, pupil size 6 to 8 |
| Cyclops robot | 48 × 40 | 12 | n/a | One eye on, larger pupil |
The four preset buttons above load similar values in one click, so it is often quickest to start from a preset and adjust.
Width and Height are in screen pixels on a 128×64 display. Keep two eyes plus the gap under about 110 pixels wide, or they will clip at the edges when the eyes look left and right. Corner radius turns a rectangle into a rounded box; set it to half the smaller side for a pill or circle. Vertical position moves both eyes up or down, which is useful when the top rows of a yellow and blue split screen are a different colour.
There are nine moods: Neutral, Happy, Angry, Sad / tired, Surprised, Suspicious, Sleepy, Love and Confused. Each one is drawn by cutting eyelids into the basic eye shape, so changing the shape changes every mood with it. A mood sequence plays moods in order, each held for its own time, and the eyes ease from one to the next rather than jumping. A good idle loop is Neutral for 6 seconds, Suspicious for 2, Neutral again, then Sleepy for 3.
Procedural code draws the eyes with shapes every frame. It is tiny, fits an Arduino Uno, and can switch mood at any time from your own code, which is why it is the default. Bitmap frames export each frame as an image instead; use them only when you need a fixed animation and have plenty of flash, such as on an ESP32. Choose Adafruit GFX if you already use that library, U8g2 for SH1106 1.3 inch screens and lower RAM use, or MicroPython for Raspberry Pi Pico and ESP32 boards running Python.
With Serial control on, open the Serial Monitor at 115200 baud and send a number from 0 to 8 to pick a mood, b to blink or r to resume the sequence. A TTP223 touch pad on the pin you enter makes the robot happy for two seconds when it is touched. The same mood numbers can be set from sensors, for example Surprised when an ultrasonic sensor sees something close, or Sleepy after a minute without movement.