Trust is earned, not given

A different perspective

2019-11-17 · Projects

A math practice toy, part 4: WiFi clock, NTP time and auto-dimming on ESP8266

Part 4from the A math practice toy series · 4 parts in all

The final form of the math toy, ESP12-MathToy-SPI-New12864, moves from Arduino Nano to ESP8266 (an ESP-12 module) and adds the three features only WiFi makes easy: an NTP-synced clock, ambient-light auto-dimming, and a shared library of helpers.

NTP time, explained simply

The Network Time Protocol lets a device ask a server "what time is it?" and get an answer accurate to milliseconds. The sketch queries an NTP pool server over UDP after boot and every hour thereafter, then keeps time locally. On the LCD, the question screen now shares space with a clock — which quietly turns the toy into a desk clock between practice sessions.

Auto-dimming with a photoresistor

A 10-cent LDR (light-dependent resistor) on an analog pin tells the sketch how bright the room is. Map the reading to the LCD backlight PWM: bright room → bright backlight, dark room → dim. The trick is debouncing the transition: apply hysteresis so the backlight does not flicker when a cloud passes. That logic later became the BacklightController library in ESP8266-Functions-Common.

Code structure

Repository: github.com/bobhuang1/ESP12-MathToy-SPI-New12864. If you are new to ESP8266, start with part 1 of the series and work forward — each step adds exactly one new concept.