Commit d6c566e1 authored by rric's avatar rric

Replace Metro by RBD::Timer (which is installable via IDE)

parent 73371d89
......@@ -16,21 +16,20 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
// Dieser Sketch verwendet die Metro-Bibliothek
// https://github.com/thomasfredericks/Metro-Arduino-Wiring
#include <Metro.h>
// Dieser Sketch verwendet die RBD::Timer-Bibliothek
#include <RBD_Timer.h>
// Der Ausgangs-Pin der LED
const int LEDPin = 11;
// Ein Metro-Objekt, das alle 1000 Millisekunden tickt
Metro ledMetro(1000);
// Der Timer zum Schalten der LED
RBD::Timer ledTimer;
void setup()
{
pinMode(LEDPin, OUTPUT);
ledTimer.setTimeout(1000);
}
// Der momentane Status der LED
......@@ -38,9 +37,10 @@ int state = LOW;
void loop()
{
// Wechsle bei jedem Tick des LED-Metro zwischen LOW und HIGH
if (ledMetro.check()) {
if (state == LOW) { // Zeile 40
// Wechsle mit jedem Restart zwischen LOW und HIGH
if (ledTimer.onRestart()) {
if (state == LOW) { // Zeile 43
state = HIGH;
}
else {
......@@ -61,7 +61,7 @@ void loop()
noch das Flackern der LED zu erkennen? Was passiert, wenn man das
Zeitintervall noch kleiner macht?
3. Finde mindestens zwei weitere Möglichkeiten, wie man in Zeile 40 ff
3. Finde mindestens zwei weitere Möglichkeiten, wie man in Zeile 43 ff
zwischen LOW und HIGH hin- und her wechseln kann.
(Hinweis: http://stackoverflow.com/questions/13154073)
......
/* SevenSegments.ino
*
* Copyright 2015 Roland Richter
* Copyright 2015, 2016 Roland Richter
*
* 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
......@@ -57,11 +57,9 @@
*/
#include <stdio.h>
#include <RBD_Timer.h>
#include <Metro.h>
Metro metro = Metro(1000);
RBD::Timer timer;
int tick = 0;
......@@ -76,15 +74,20 @@ void setup()
pinMode(A2, OUTPUT);
pinMode(A3, OUTPUT);
while (!metro.check()) {
timer.setTimeout(1000);
timer.restart();
while (timer.isActive()) {
displayString("Ardu");
}
while (!metro.check()) {
timer.restart();
while (timer.isActive()) {
displayString(" ino");
}
metro.interval(100);
timer.setTimeout(100);
}
......@@ -102,7 +105,7 @@ void loop()
displayString(str);
if (metro.check()) {
if (timer.onRestart()) {
tick = (++tick % NTicks);
}
}
......
/* Temperatur.ino
*
* Copyright 2013, 2014, 2015 Roland Richter
* Copyright 2013, 2014, 2015, 2016 Roland Richter
*
* 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
......@@ -29,7 +29,7 @@
* for more info.
*/
#include <Metro.h>
#include <RBD_Timer.h>
#include <OneWire.h>
#include <DallasTemperature.h>
......@@ -44,11 +44,13 @@ DallasTemperature sensor(&oneWire);
// Connect LCD shield to pin 8, if any.
SoftwareSerial s7s(7, 8);
Metro tick = Metro(6000);
RBD::Timer tick;
void setup(void)
{
tick.setTimeout(6000);
sensor.begin();
Serial.begin(9600);
......@@ -68,7 +70,7 @@ void setup(void)
void loop(void)
{
if (tick.check() == 1) {
if (tick.onRestart()) {
// Measure temperature in Celsius every six seconds, ...
double currentTime = ((float)millis()) / (60. * 1000.);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment