Pages: [1]   Go Down
Author Topic: WAKEUP - a simply library to manage counters  (Read 1091 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 13
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Hi there,

i'm sharing WAKEUP my first library here.  It's a simple way to manipulate counters and timers in your sketch.
(zip attached or https://github.com/brunocadet/WAKEUP)

Example of a counter : Blinking a LED
Code:
WAKEUP myLed;

void loop(){
if ( myLed.istime(500) ) digitalWrite( 13, !digitalRead(13) );  
}

Example of a timer
Code:
WAKEUP myTimer(30000);

void loop(){
if ( digitalRead(bouton) ) myTimer.go();
if ( myTimer.istime() ) Serial.print("DEBOUT LADANS!");  
}

Enjoy.

* WAKEUP.zip (5.78 KB - downloaded 7 times.)
Logged

Global Moderator
Netherlands
Offline Offline
Shannon Member
*****
Karma: 212
Posts: 13531
In theory there is no difference between theory and practice, however in practice there are many...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset


TIP: make the time related variables unsigned long instead of  long ==> matches the values returned by millis() .
also for return values of some functions e.g.

Code:
long WAKEUP::remain(){
  return max(0, start+life-millis());
}

Code:
unsigned long WAKEUP::remain()
{
  unsigned long current = millis();
  if (current < start +life) return start + life - current;
  return 0;
}
Logged

Rob Tillaart

Nederlandse sectie - http://arduino.cc/forum/index.php/board,77.0.html -
(Please do not PM for private consultancy)

Pages: [1]   Go Up
Jump to: