None Notebook

This notebook contains material from cbe61622; content is available on Github.

< 2.4 Ultrasonic Distance Ranger | Contents | 3.0 Enabling the Internet of Things >

Open in Colab

Download

2.5 Simple Stop Watch using Interrupts

2.5.1 Particle CLI

2.5.1.1 Installation

2.5.1.2 Utility functions

2.5.1.3 Login to Particle

2.5.1.4 Select a device

The following cell downloads a list of all user devices and creates a list of device names. Here we choose the first name in the list for the rest of this notebook. If this is not the device to be used, then modify this cell accordingly.

2.5.2 Project: Simple Stop Watch

The goal of this project is to build a simple stop watch. The project will use code previously developed for the Grove 4 digit display, and add a Grove button to control operation of the stop watch. The stop watch will start and stop with a short click of the button, and reset to zero with a long button press.

2.5.2.1 Grove Button

The Grove Button is a momentary contact with a pull-down resistor. With a pull-down resistor, the pin value is LOW when the button is not pressed, and become HIGH when the button is depressed.

2.5.3 Solution 1: Using clickButton library

2.5.3.1 Create Project

2.5.3.2 Change working directory

The Particle CLI assumes one is working in the top project directory.

2.5.3.3 Add relevant libraries

2.5.3.4 Create source file

2.5.3.5 Compiling

2.5.3.6 Flash firmware

2.5.4 Solution 2: Interrupt Service Routine (ISR)

The clickButton library provides an easy-to-use method of managing the button actions, with provisions for debouncing, multiple clicks, and long clicks, but testing shows the button updates when the button is released, not when it is pressed. This is not consistent with a user's expectation that the clock should stop and start on the press of the button, not on the release.

The following cell demonstrates the use of an Interrupt Service Routine to manage the button interface. The key insight here is to respond to both the press and release of the button by specifying CHANGE in the attachInterrupt function. This makes is possible to detect a long button press to reset the stop watch display to zero.

< 2.4 Ultrasonic Distance Ranger | Contents | 3.0 Enabling the Internet of Things >

Open in Colab

Download