From 0f33d88c94eafcfe980a56ab66d0d2c0e574968c Mon Sep 17 00:00:00 2001 From: Jonas Smedegaard Date: Sun, 9 Mar 2025 15:25:02 +0100 Subject: separate function read() from main loop() --- mussel1/mussel1.ino | 16 ++++++++++------ mussel2/mussel2.ino | 16 ++++++++++------ 2 files changed, 20 insertions(+), 12 deletions(-) diff --git a/mussel1/mussel1.ino b/mussel1/mussel1.ino index 679e225..28c8097 100644 --- a/mussel1/mussel1.ino +++ b/mussel1/mussel1.ino @@ -16,16 +16,20 @@ void setup() { } void loop() { - // Get the current second (0-59) - unsigned long currentTime = millis(); - unsigned long totalSeconds = currentTime / 1000; - unsigned long currentSecond = totalSeconds % 60; - String msg = "good"; - if (currentSecond >= 50) + if (read() >= 50) msg = "bad"; Serial.printf("*** NOTIFY: %s ***\n", msg); delay(1000); } + +byte read() { + // Get the current second (0-59) + unsigned long currentTime = millis(); + unsigned long totalSeconds = currentTime / 1000; + unsigned long currentSecond = totalSeconds % 60; + + return (byte)currentSecond; +} diff --git a/mussel2/mussel2.ino b/mussel2/mussel2.ino index 6ffb876..dc0a298 100644 --- a/mussel2/mussel2.ino +++ b/mussel2/mussel2.ino @@ -16,16 +16,20 @@ void setup() { } void loop() { - // Get second-long cyclic counter 0-11 - unsigned long currentTime = millis(); - unsigned long totalSeconds = currentTime / 1000; - unsigned long currentSecond = totalSeconds % 12; - String msg = "good"; - if (currentSecond >= 9) + if (read() >= 9) msg = "bad"; Serial.printf("*** NOTIFY: %s ***\n", msg); delay(1000); } + +byte read() { + // Get second-long cyclic counter 0-11 + unsigned long currentTime = millis(); + unsigned long totalSeconds = currentTime / 1000; + unsigned long currentSecond = totalSeconds % 12; + + return (byte)currentSecond; +} -- cgit v1.2.3