Skip to content
This repository was archived by the owner on Aug 25, 2025. It is now read-only.
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file added Metro/.DS_Store
Binary file not shown.
129 changes: 107 additions & 22 deletions Metro/Metro.cpp
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -9,53 +9,138 @@

Metro::Metro()
{

this->interval_millis = 1000;

}

number_of_executions = 0;

}

Metro::Metro(unsigned long interval_millis)
{


number_of_executions = 1;
this->interval_millis = interval_millis;

}

}

void Metro::interval(unsigned long interval_millis)
{

previous_millis = millis();
this->interval_millis = interval_millis;
this->number_of_executions = 1;
count_down_enabled = false;

}

void Metro::timeout(unsigned long interval_millis)
{

previous_millis = millis();
this->interval_millis = interval_millis;
this->number_of_executions = 1;
count_down_enabled = true;

}

void Metro::countedExecutions(unsigned long interval_millis, unsigned long number_of_executions)
{

previous_millis = millis();
this->interval_millis = interval_millis;
this->number_of_executions = number_of_executions;
count_down_enabled = true;

}

void Metro::addExecutions(unsigned long number_of_executions)
{

this->number_of_executions += number_of_executions;
count_down_enabled = true;

}

void Metro::setExecutions(unsigned long number_of_executions)
{

this->number_of_executions = number_of_executions;
count_down_enabled = true;

}

uint8_t Metro::check()
{

unsigned long now = millis();

if ( interval_millis == 0 ){
unsigned long now = millis();

if(EXECUTE_ON_START && previous_millis == 0){
previous_millis = millis();
Serial.println("innerTrig!!");
return 1;
}

if ( interval_millis == 0 && number_of_executions > 0) {
if( count_down_enabled ) {
number_of_executions--;
}
previous_millis = now;
return 1;
return 1;
}

if ( (now - previous_millis) >= interval_millis) {
#ifdef NOCATCH-UP
previous_millis = now ;
#else
previous_millis += interval_millis ;
#endif

if ( (now - previous_millis) >= interval_millis && number_of_executions > 0) {
if( !CATCH_UP ) {
previous_millis = now;
}
else{
previous_millis += interval_millis;
}

if( count_down_enabled ) {
number_of_executions--;
}
return 1;
}

return 0;

}

void Metro::reset()
void Metro::reset()
{

this->previous_millis = millis();

if(EXECUTE_ON_START){
this->previous_millis = 0;
}
else{
this->previous_millis = millis();
}

if(count_down_enabled){
number_of_executions = previous_number_of_executions;
}else{
number_of_executions = 1;
}

}

void Metro::stop()
{

previous_number_of_executions = number_of_executions;
number_of_executions = 0;

}

void Metro::setCatchUp(bool CATCH_UP)
{

this->CATCH_UP = CATCH_UP;

}

void Metro::setExecuteOnStart(bool EXECUTE_ON_START)
{

this->EXECUTE_ON_START = EXECUTE_ON_START;

}
23 changes: 16 additions & 7 deletions Metro/Metro.h
100644 → 100755
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,12 @@
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
Expand All @@ -18,7 +18,7 @@



/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
Main code by Thomas O Fredericks (tof@t-o-f.info)
Contributions by Paul Bouchier and Benjamin.soelberg
* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
Expand All @@ -36,14 +36,23 @@ class Metro
Metro();
Metro(unsigned long interval_millis);
void interval(unsigned long interval_millis);
void timeout(unsigned long interval_millis);
void countedExecutions(unsigned long interval_millis, unsigned long number_of_executions);
void addExecutions(unsigned long number_of_executions);
void setExecutions(unsigned long number_of_executions);
uint8_t check();
void reset();

void stop();
void setCatchUp(bool CATCH_UP);
void setExecuteOnStart(bool EXECUTE_ON_START);

private:
unsigned long previous_millis, interval_millis;
unsigned long previous_millis, interval_millis, number_of_executions, previous_number_of_executions;
bool count_down_enabled;

bool CATCH_UP = false;
bool EXECUTE_ON_START = false;

};

#endif


5 changes: 2 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@ Metro library for Arduino or Wiring that facilitates the implementation of recur
by Thomas Ouellet Fredericks
with contributions from: Paul Bouchier and Benjamin.soelberg

Download the latest version here : https://github.com/thomasfredericks/Metro-Arduino-Wiring/archive/master.zip

Documentation can be found here : https://github.com/thomasfredericks/Metro-Arduino-Wiring/wiki
-------------

MY FORK of this library offers many more advanced features!