Stopwatch

Article thumbnail

Published

arduino software 7-segment-shield

Creating a stopwatch with an Arduino and a seven-segment shield

Overview

This page was updated in 2020 to use the SevenSegmentShield library. For a download and more information, follow this guide.

This code uses the Gravitech seven-segment shield.

Code

This is a simple program that counts up every second and displays the counter on the segments, similar to a stopwatch.

/*
  Stopwatch
  Displays numbers on a seven segment display shield like a stopwatch.
  Parts required:
  Arduino Uno
  Seven segment shield
*/

#include <SevenSegmentShield.h> // Include shield library
#include <Wire.h> // Include Wire library for I2C

Display ds;    // Create Display object to use
int count = 0; // The variable to display

void setup() {
  Wire.begin(); // Init I2C bus
  ds.begin();   // Init display
}

void loop() {
  ds.displayInt(count++); // Increment count and display on segments
  delay(1000);            // Wait one second before continuing
}