0% found this document useful (0 votes)
94 views2 pages

Simple Timer

A timer library is used to call three different timers: 1) A timer that calls a function every 15 seconds to print a message. 2) A timer that calls a function once after 10 seconds to print a single message. 3) A timer that calls a function 10 times every second to print a count. The timers are set up in the setup function and a clock is also displayed.

Uploaded by

jm.hupont
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
94 views2 pages

Simple Timer

A timer library is used to call three different timers: 1) A timer that calls a function every 15 seconds to print a message. 2) A timer that calls a function once after 10 seconds to print a single message. 3) A timer that calls a function 10 times every second to print a count. The timers are set up in the setup function and a clock is also displayed.

Uploaded by

jm.hupont
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

/*

* [Link]
*
* Based on usage example for Time + TimeAlarm libraries
*
* A timer is called every 15 seconds
* Another timer is called once only after 10 seconds
* A third timer is called 10 times.
*
*/

#include <SimpleTimer.h>

// There must be one global SimpleTimer object.


// More SimpleTimer objects can be created and run,
// although there is little point in doing so.
SimpleTimer timer;

// function to be called repeatedly


void RepeatTask() {
[Link]("15 second timer");
}

// function to be called just once


void OnceOnlyTask() {
[Link]("This timer only triggers once");
}

// function to be called exactly 10 times


void TenTimesTask() {
static int k = 0;
k++;
[Link]("called ");
[Link](k);
[Link](" / 10 times.");
}

// print current arduino "uptime" on the serial port


void DigitalClockDisplay() {
int h,m,s;
s = millis() / 1000;
m = s / 60;
h = s / 3600;
s = s - m * 60;
m = m - h * 60;
[Link](h);
printDigits(m);
printDigits(s);
[Link]();
}

//
// utility function for digital clock display:
// prints preceding colon and leading 0
//
void printDigits(int digits) {
[Link](":");
if(digits < 10)
[Link]('0');
[Link](digits);
}

void setup() {
[Link](9600);

// welcome message
[Link]("SimpleTimer Example");
[Link]("One timer is triggered every 15 seconds");
[Link]("Another timer is set to trigger only once after 10 seconds");
[Link]("Another timer is set to trigger 10 times");
[Link]();

// timed actions setup


[Link](15000, RepeatTask);
[Link](10000, OnceOnlyTask);
[Link](1000, DigitalClockDisplay);
[Link](1200, TenTimesTask, 10);
}

void loop() {
// this is where the "polling" occurs
[Link]();
}

You might also like