How to use
tell Arduino that you want to use this library.#include <Metro.h>
Instantiate a Metro object at the top of the sketch like this:
Metro led_metro = Metro(250);
In the preceding example, a Metro named "led_metro" was created with an interval of 250 milliseconds. You can now control this Metro through this new "led_metro" variable.
Because Metro does not use interrupts, you have to "check" the Metro regularly (at least every millisecond) like this:
led_metro.check()
check() will return 1 if 250 milliseconds have passed, 0 if not.
To change the interval to 1 second use interval() like this:
led_metro.interval(1000)
To restart/reset the Metro, use reset():
led_metro.reset()
#include <Metro.h>
/*
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.
*/
// Instantiate a metro object and set the interval to 250 milliseconds (0.25 seconds).
Metro led_metro = Metro(250);
void setup()
{
pinMode(13,OUTPUT);
digitalWrite(13,HIGH);
}
void loop()
{
if (led_metro.check() == 1) { // check if the metro has passed it's interval .
digitalWrite(13,!digitalRead(13)); // change the state of pin 13.
if (digitalRead(13)==HIGH) {
led_metro.interval(250); // if the pin is HIGH, set the interval to 0.25 seconds.
}
else {
led_metro.interval(1000); // if the pin is LOW, set the interval to 1 second.
}
}
}