initial
This commit is contained in:
20
Metro/LICENSE
Normal file
20
Metro/LICENSE
Normal file
@@ -0,0 +1,20 @@
|
||||
The MIT License (MIT)
|
||||
|
||||
Copyright (c) 2013 thomasfredericks
|
||||
|
||||
Permission is hereby granted, free of charge, to any person obtaining a copy of
|
||||
this software and associated documentation files (the "Software"), to deal in
|
||||
the Software without restriction, including without limitation the rights to
|
||||
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of
|
||||
the Software, and to permit persons to whom the Software is furnished to do so,
|
||||
subject to the following conditions:
|
||||
|
||||
The above copyright notice and this permission notice shall be included in all
|
||||
copies or substantial portions of the Software.
|
||||
|
||||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS
|
||||
FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR
|
||||
COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER
|
||||
IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN
|
||||
CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
||||
61
Metro/Metro.cpp
Normal file
61
Metro/Metro.cpp
Normal file
@@ -0,0 +1,61 @@
|
||||
|
||||
|
||||
#if defined(ARDUINO) && ARDUINO >= 100
|
||||
#include "Arduino.h"
|
||||
#else
|
||||
#include "WProgram.h"
|
||||
#endif
|
||||
#include "Metro.h"
|
||||
|
||||
Metro::Metro()
|
||||
{
|
||||
|
||||
this->interval_millis = 1000;
|
||||
|
||||
}
|
||||
|
||||
|
||||
Metro::Metro(unsigned long interval_millis)
|
||||
{
|
||||
|
||||
this->interval_millis = interval_millis;
|
||||
|
||||
}
|
||||
|
||||
|
||||
void Metro::interval(unsigned long interval_millis)
|
||||
{
|
||||
this->interval_millis = interval_millis;
|
||||
}
|
||||
|
||||
uint8_t Metro::check()
|
||||
{
|
||||
|
||||
unsigned long now = millis();
|
||||
|
||||
if ( interval_millis == 0 ){
|
||||
previous_millis = now;
|
||||
return 1;
|
||||
}
|
||||
|
||||
if ( (now - previous_millis) >= interval_millis) {
|
||||
#ifdef NOCATCH-UP
|
||||
previous_millis = now ;
|
||||
#else
|
||||
previous_millis += interval_millis ;
|
||||
#endif
|
||||
return 1;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
||||
}
|
||||
|
||||
void Metro::reset()
|
||||
{
|
||||
|
||||
this->previous_millis = millis();
|
||||
|
||||
}
|
||||
|
||||
|
||||
49
Metro/Metro.h
Normal file
49
Metro/Metro.h
Normal file
@@ -0,0 +1,49 @@
|
||||
|
||||
/*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* 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,
|
||||
* MA 02110-1301, USA.
|
||||
*/
|
||||
|
||||
|
||||
|
||||
/* * * * * * * * * * * * * * * * * * * * * * * * * * * *
|
||||
Main code by Thomas O Fredericks (tof@t-o-f.info)
|
||||
Contributions by Paul Bouchier and Benjamin.soelberg
|
||||
* * * * * * * * * * * * * * * * * * * * * * * * * * * * */
|
||||
|
||||
#ifndef Metro_h
|
||||
#define Metro_h
|
||||
|
||||
#include <inttypes.h>
|
||||
|
||||
|
||||
class Metro
|
||||
{
|
||||
|
||||
public:
|
||||
Metro();
|
||||
Metro(unsigned long interval_millis);
|
||||
void interval(unsigned long interval_millis);
|
||||
uint8_t check();
|
||||
void reset();
|
||||
|
||||
private:
|
||||
unsigned long previous_millis, interval_millis;
|
||||
|
||||
};
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
1
Metro/README.md
Normal file
1
Metro/README.md
Normal file
@@ -0,0 +1 @@
|
||||
Please visit https://github.com/thomasfredericks/Metro-Arduino-Wiring for latest code and documentation.
|
||||
30
Metro/examples/blinking/blinking.ino
Normal file
30
Metro/examples/blinking/blinking.ino
Normal file
@@ -0,0 +1,30 @@
|
||||
/*
|
||||
This code will blink an LED attached to pin 13 on and off.
|
||||
It will stay on for 0.25 seconds.
|
||||
It will stay off for 1 second.
|
||||
*/
|
||||
#include <Metro.h> //Include Metro library
|
||||
#define LED 13 // Define the led's pin
|
||||
|
||||
//Create a variable to hold theled's current state
|
||||
int state = HIGH;
|
||||
|
||||
// Instanciate a metro object and set the interval to 250 milliseconds (0.25 seconds).
|
||||
Metro ledMetro = Metro(250);
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(LED,OUTPUT);
|
||||
digitalWrite(LED,state);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
if (ledMetro.check() == 1) { // check if the metro has passed its interval .
|
||||
if (state==HIGH) state=LOW;
|
||||
else state=HIGH;
|
||||
|
||||
digitalWrite(LED,state);
|
||||
}
|
||||
}
|
||||
51
Metro/examples/blinking_2_instances/blinking_2_instances.ino
Normal file
51
Metro/examples/blinking_2_instances/blinking_2_instances.ino
Normal file
@@ -0,0 +1,51 @@
|
||||
// This code will blink output 13 every 250 ms
|
||||
// abd will blink output 9 every 125 ms
|
||||
|
||||
|
||||
#include <Metro.h> // Include Metro library
|
||||
#define LED0 13 // Define a LED pin
|
||||
#define LED1 9 // Define another LED pin
|
||||
|
||||
// Create variables to hold the LED states
|
||||
int state0 = HIGH;
|
||||
int state1 = HIGH;
|
||||
|
||||
// Instantiate a metro object and set the interval to 250 milliseconds (0.25 seconds).
|
||||
Metro metro0 = Metro(250);
|
||||
|
||||
// Instantiate another metro object and set the interval to 125 milliseconds (0.125 seconds).
|
||||
Metro metro1 = Metro(125);
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(LED0,OUTPUT);
|
||||
digitalWrite(LED0,state0);
|
||||
|
||||
pinMode(LED1,OUTPUT);
|
||||
digitalWrite(LED1,state1);
|
||||
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
if (metro0.check() == 1) { // check if the metro has passed its interval .
|
||||
if (state0==HIGH) {
|
||||
state0=LOW;
|
||||
} else {
|
||||
state0=HIGH;
|
||||
}
|
||||
digitalWrite(LED0,state0);
|
||||
}
|
||||
|
||||
if (metro1.check() == 1) { // check if the metro has passed its interval .
|
||||
if (state1==HIGH) {
|
||||
state1=LOW;
|
||||
} else {
|
||||
state1=HIGH;
|
||||
}
|
||||
digitalWrite(LED1,state1);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
36
Metro/examples/blinking_2_intervals/blinking_2_intervals.ino
Normal file
36
Metro/examples/blinking_2_intervals/blinking_2_intervals.ino
Normal file
@@ -0,0 +1,36 @@
|
||||
/*
|
||||
This code will blink an LED attached to pin 13 on and off.
|
||||
It will stay on for 0.25 seconds.
|
||||
It will stay off for 1 second.
|
||||
*/
|
||||
#include <Metro.h> //Include Metro library
|
||||
#define LED 13 // Define the led's pin
|
||||
|
||||
//Create a variable to hold theled's current state
|
||||
int state = HIGH;
|
||||
|
||||
// Instanciate a metro object and set the interval to 250 milliseconds (0.25 seconds).
|
||||
Metro ledMetro = Metro(250);
|
||||
|
||||
void setup()
|
||||
{
|
||||
pinMode(LED,OUTPUT);
|
||||
digitalWrite(LED,state);
|
||||
}
|
||||
|
||||
void loop()
|
||||
{
|
||||
|
||||
if (ledMetro.check() == 1) { // check if the metro has passed its interval .
|
||||
if (state==HIGH) {
|
||||
state=LOW;
|
||||
ledMetro.interval(250); // if the pin is HIGH, set the interval to 0.25 seconds.
|
||||
}
|
||||
else {
|
||||
ledMetro.interval(1000); // if the pin is LOW, set the interval to 1 second.
|
||||
state=HIGH;
|
||||
}
|
||||
digitalWrite(LED,state);
|
||||
}
|
||||
}
|
||||
|
||||
24
Metro/examples/serialInterval/serialInterval.ino
Normal file
24
Metro/examples/serialInterval/serialInterval.ino
Normal file
@@ -0,0 +1,24 @@
|
||||
// This example sends a Serial message every 250 milliseconds
|
||||
|
||||
#include <Metro.h> // Include the Metro library
|
||||
|
||||
Metro serialMetro = Metro(250); // Instantiate an instance
|
||||
|
||||
void setup() {
|
||||
Serial.begin(115200); // Start the Serial communication
|
||||
}
|
||||
|
||||
void loop() {
|
||||
|
||||
if (serialMetro.check() == 1) { // check if the metro has passed it's interval .
|
||||
// Output all the analog readings seperated by a space character
|
||||
for (int i = 0; i < 6; i++ ) {
|
||||
Serial.print (analogRead( i) );
|
||||
Serial.print(32,BYTE);
|
||||
}
|
||||
// Terminate message with a linefeed and a carriage return
|
||||
Serial.print(13,BYTE);
|
||||
Serial.print(10,BYTE);
|
||||
}
|
||||
}
|
||||
|
||||
25
Metro/keywords.txt
Normal file
25
Metro/keywords.txt
Normal file
@@ -0,0 +1,25 @@
|
||||
#######################################
|
||||
# Syntax Coloring Map For Test
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Datatypes (KEYWORD1)
|
||||
#######################################
|
||||
|
||||
Metro KEYWORD1
|
||||
|
||||
#######################################
|
||||
# Methods and Functions (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
check KEYWORD2
|
||||
interval KEYWORD2
|
||||
|
||||
#######################################
|
||||
# Instances (KEYWORD2)
|
||||
#######################################
|
||||
|
||||
#######################################
|
||||
# Constants (LITERAL1)
|
||||
#######################################
|
||||
|
||||
Reference in New Issue
Block a user