Manual Reset

A Timer is typically used in manual-mode to control the duration of a punctual task.

In this example, you will see how to use a HITI Timer in manual-reset to trigger the lighting of the on-board LED for 2 seconds. The LED is turned on when the Timer starts and is turned off when the Timer ends.

The Timer is reset using a Virtual Switch. When the program starts, the Timer immediately runs once. Then an action on the Virtual Switch is required to restart the Timer.


1) Sketch: 2_Timing \ 2_TimerManualReset

We start our code by creating a HITI Timer variable (HC_Timer timer).

Then, during the setup(), we declare pin 13 as an output to control the on-board LED. We also set the Timer to manual-reset using manualReset().

#include <HITIComm.h>

// pins assignment
const byte pin_LED = LED_BUILTIN;

// Digital Data assignment
const byte dd_ResetSwitch = 0;

// Analog Data assignment
const byte ad_StartTime   = 0;
const byte ad_ElapsedTime = 1;

// HITI Timer
HC_Timer timer;

// run once at power on
void setup()
    // initialize library

    // set pins mode
    pinMode(pin_LED, OUTPUT);

    // set Timer to manual reset mode

Inside the loop(), we start and run the Timer using its delay(duration) function. When the Timer starts, the LED is turned on. Then, after a duration of 2000ms, the Timer ends, and the LED is turned off. We use isStarting() to know when the Timer starts and delay(duration) to know when the Timer ends.

Then, we check if the Virtual Switch has been activated (using the DIGITAL DATA Control Panel). If so, we immediately deactivate it and we reset() the Timer. The reset only works if the Timer has ended.

Finally, we write the Timer Start Time and Elapsed Time in Analog Data to watch them inside the ANALOG DATA Control Panel.

// run repeatedly after setup()
void loop()
    // communicate with HITIPanel

    // when Timer starts
    if (timer.isStarting())
        digitalWrite(pin_LED, HIGH); 

    // after 2000 ms
    if (timer.delay(2000))
        digitalWrite(pin_LED, LOW); 

    // reset Timer using the Virtual Switch 
    if (HC_digitalDataRead(dd_ResetSwitch) == HIGH)
        // reset Timer

        // deactivate Virtual Switch
        HC_digitalDataWrite(dd_ResetSwitch, LOW);

    // monitor Start Time and Elapsed Time
    HC_analogDataWrite(ad_StartTime,   timer.getStartTime());
    HC_analogDataWrite(ad_ElapsedTime, timer.getElapsedTime());


2) Control Panels

  1. Display the HITI DATA Control Panels (“HITI” button).
  2. Reset and restart the Timer. Check that the on-board LED does turn on for 2s. Also, check the Elapsed Time. Repeat this operation several times and see how the Timer Start Time increases each time. This value is referenced to the program start time. In our example, the last time the Timer was started is 21654ms after the program began to run.



Was this article helpful?
0 out of 0 found this helpful