Practice Exercise: Outputs

Table of contents

  1. Going Further

This practice exercise will challenge you to create a countdown timer using either a solenoid, a piezo, or a neopixel strip. You’ll get familiar with using millis() to program change and transitions over time as part of your hardware prototypes.

You’ll also need to wire up a pushbutton.

As part of this exercise, you’ll need to

  • Create a circuit containing the solenoid, a piezo, or a neopixel strip and a pushbutton.

  • Create code that does the following:

    • Includes the necessary libraries e.g. the neopixel library
    • Contains a seires of variables for the pins you’re using.
    • Has cloud variables that allow you to see if the timer is running and the amount of time remaining online
    • Uses setup to configure the pins in use and initialize libraries
      • Contains Particle cloud function(s) to start and stop the timer.
      • Has code that allows the pushbutton to start and stop the timer too.
      • Add a default time of 5 minutes for the timer.

The component should behave as follows:

Solenoid

On startup:

  • It should tap three times quickly to indicate the timer is started.

When the timer is running it should:

  • Tap once after each minute elapses;
  • Tap in a unique way to indicate one minute remaining;
  • Alternate taps on and off for the last 15 seconds (e.g. 1 second on, 1 second off)
  • Tap to indicate the time has completely elapsed.

Neopixel

On startup:

  • Fade up all of the LEDS i.e. progressively turn on all of the LEDs, one by one.

When the timer is running it should:

  • Map the time remaining to the number of LEDs illuminated, e.g. after 2.5 minutes half the LEDs should be off.
  • When one minute is remaining change the color of the LEDs to red.
  • When 15 seconds is remaining flash or pulse the LEDs
  • Flash all of the LEDS five times to indicate the time has completely elapsed.

Piezo

On startup:

  • Play a short melody to indicate the timer has begun.

When the timer is running it should:

  • Beep after each minute elapses;
  • Play a short tone/melody to indicate one minute remaining;
  • Play a short tone each second to count down the last 15 seconds.
  • Play a distinct melody to indicate the time has completely elapsed.

Going Further

Once you’ve achieved the outcome, you can try some of the below and experiment to improve your coding skills

Exercise 1

Add a Particle.function to customize the time / duration of the countdown

Exercise 2

Allow the pushbutton to pause the timer if pressed while the timer is running and use a double press to cancel it / reset it


Table of contents