Community project

STOPWATCH

Photo of STOPWATCH

Khang

Published November 28, 2026

This ESP32-based stopwatch project delivers precise time measurement with a clean, seven-segment display interface. Built around the UNIHIKER K10 platform with its integrated touchscreen, the stopwatch provides start, stop, and reset functionality through physical buttons, making it ideal for timing experiments, workouts, or any maker project requiring accurate elapsed time tracking.

The guide includes a complete wiring diagram, parts list, and step-by-step assembly instructions for the cam cap USB configuration. Firmware with debounced button input and LVGL-based display rendering is provided, allowing builders to customize timing features or integrate the stopwatch into larger projects.

Wiring diagram

Wiring diagram for STOPWATCH
Loading diagram…

Assemble it in 1 step

1. Cam cap USB

Dung cap USB co truyen du lieu de noi K10 voi may tinh. Khong can linh kien hay day noi ngoai.

Deploy the firmware

#include <Arduino.h>
#include <unihiker_k10.h>
#include <lvgl.h>

UNIHIKER_K10 k10;
struct StopwatchKey {
  bool raw=false, stable=false;
  uint32_t changed=0;
  bool pressed(bool sample,uint32_t now){
    if(sample!=raw){raw=sample;changed=now;}
    if(raw!=stable && now-changed>=25){stable=raw;return stable;}
    return false;
  }
} a,b;

lv_obj_t *segments[7][7], *state, *action, *progress;
int previous[7]={-1,-1,-1,-1,-1,-1,-1};
bool running=false;
uint32_t last=0;
uint64_t elapsed=0;
constexpr uint32_t mint=0x62F5CD, ink=0x111F33, muted=0x93ACC5;
constexpr uint32_t digitWhite=0xFFFFFF;

lv_obj_t *tile(lv_obj_t *parent,int w,int h,int radius,uint32_t color){
  auto *o=lv_obj_create(parent);
  lv_obj_remove_style_all(o);
  lv_obj_clear_flag(o,LV_OBJ_FLAG_SCROLLABLE);
  lv_obj_set_size(o,w,h);
  lv_obj_set_style_radius(o,radius,0);
  lv_obj_set_style_bg_opa(o,LV_OPA_COVER,0);
  lv_obj_set_style_bg_color(o,lv_color_hex(color),0);
  return o;
}
lv_obj_t *caption(lv_obj_t *parent,const char *s,uint32_t color,lv_align_t align,int x,int y){
  auto *o=lv_label_create(parent);
  lv_label_set_text(o,s);
  lv_obj_set_style_text_color(o,lv_color_hex(color),0);
  lv_obj_align(o,align,x,y);
  return o;
}
void digit(int i,int n){
  if(previous[i]==n)return;
  previous[i]=n;
  const uint8_t masks[]={63,6,91,79,102,109,125,7,127,111};
  for(int j=0;j<7;j++)lv_obj_set_style_bg_color(segments[i][j],lv_color_hex((masks[n]>>j)&1?digitWhite:ink),0);
}
void setup(){
  k10.begin();
  k10.initScreen(2);
  auto *s=lv_scr_act();
  lv_obj_clear_flag(s,LV_OBJ_FLAG_SCROLLABLE);
  lv_obj_set_style_bg_color(s,lv_color_hex(0x091321),0);
  auto *mark=tile(s,5,20,2,mint);
  lv_obj_align(mark,LV_ALIGN_TOP_LEFT,14,14);
  caption(s,"STOPWATCH",0xFFFFFF,LV_ALIGN_TOP_LEFT,27,16);
  caption(s,"K10",muted,LV_ALIGN_TOP_RIGHT,-14,16);
  auto *card=tile(s,lv_pct(92),140,18,ink);
  lv_obj_align(card,LV_ALIGN_CENTER,0,-2);
  state=caption(card,"READY",mint,LV_ALIGN_TOP_MID,0,10);
  auto *face=tile(card,196,38,0,ink);
  lv_obj_align(face,LV_ALIGN_CENTER,0,-3);
  const int dx[]={0,25,56,81,112,137,169};
  const int x[]={4,18,18,4,0,0,4}, y[]={0,4,20,34,20,4,17};
  for(int i=0;i<7;i++)for(int j=0;j<7;j++){
    bool horizontal=j==0 || j==3 || j==6;
    segments[i][j]=tile(face,horizontal?14:4,horizontal?4:14,2,ink);
    lv_obj_set_pos(segments[i][j],dx[i]+x[j],y[j]);
  }
  for(int xPos:{49,105,162}){
    lv_obj_set_pos(tile(face,4,4,2,digitWhite),xPos,26);
    if(xPos!=162)lv_obj_set_pos(tile(face,4,4,2,digitWhite),xPos,10);
  }
  caption(card,"HOURS     MIN     SEC     TENTHS",muted,LV_ALIGN_BOTTOM_MID,0,-28);
  auto *track=tile(card,184,4,2,0x243B51);
  lv_obj_align(track,LV_ALIGN_BOTTOM_MID,0,-14);
  progress=tile(track,1,4,2,mint);
  auto *left=tile(s,100,32,10,0x163D3B);
  auto *right=tile(s,100,32,10,ink);
  lv_obj_align(left,LV_ALIGN_BOTTOM_MID,-55,-10);
  lv_obj_align(right,LV_ALIGN_BOTTOM_MID,55,-10);
  action=caption(left,"A  Start",mint,LV_ALIGN_CENTER,0,0);
  caption(right,"B  Reset",0xFFFFFF,LV_ALIGN_CENTER,0,0);
}
void loop(){
  uint32_t now=millis();
  if(running) elapsed+=uint32_t(now-last);
  last=now;
  bool toggle=a.pressed(k10.buttonA->isPressed(),now);
  if(b.pressed(k10.buttonB->isPressed(),now)){running=false;elapsed=0;}
  else if(toggle) running=!running;
  unsigned t=elapsed/100%3600000;
  const int values[]={int(t/360000),int(t/36000%10),int(t/6000%6),int(t/600%10),int(t/100%6),int(t/10%10),int(t%10)};
  for(int i=0;i<7;i++)digit(i,values[i]);
  static unsigned phase=60;
  unsigned next=t/10%60;
  if(phase!=next){phase=next;lv_obj_set_width(progress,1+next*183/59);}
  const char *status=running?"RUNNING":elapsed?"PAUSED":"READY";
  const char *control=running?"A  Pause":elapsed?"A  Resume":"A  Start";
  if(strcmp(lv_label_get_text(state),status))lv_label_set_text(state,status);
  if(strcmp(lv_label_get_text(action),control))lv_label_set_text(action,control);
  lv_timer_handler();
  delay(5);
}

Remix this project

Make it yours in one click

Open a full copy of this project in your own Schematik workspace, diagram, code, parts, and assembly steps included. Swap the sensor, add features, or redesign the whole thing with AI. The author's original stays untouched.

Open in Schematik