From 21a4bfa739ecb69b9b816e9709d12f5dc78b0dd6 Mon Sep 17 00:00:00 2001 From: alanbjohnston Date: Fri, 15 Jul 2022 10:05:59 -0400 Subject: [PATCH] check for button press once per loop --- cubesatsim/cubesatsim.ino | 15 ++++++++------- 1 file changed, 8 insertions(+), 7 deletions(-) diff --git a/cubesatsim/cubesatsim.ino b/cubesatsim/cubesatsim.ino index f4225384..219c294e 100644 --- a/cubesatsim/cubesatsim.ino +++ b/cubesatsim/cubesatsim.ino @@ -140,6 +140,13 @@ void loop() { config_telem(); config_radio(); } + + +// check for button press + if (digitalRead(MAIN_PB_PIN) == PRESSED) // pushbutton is pressed + process_pushbutton(); + if (BOOTSEL) // boot selector button is pressed on Pico + process_bootsel(); // Calculate loop time Serial.print("\nLoop time: "); @@ -2479,13 +2486,7 @@ void sleep(float time) { // sleeps for intervals more than 0.01 milli seconds unsigned long startSleep = micros(); while ((micros() - startSleep) < time_us) { // busy_wait_us(100); - delayMicroseconds(100); - -// check for button press upon coming out of sleep - if (digitalRead(MAIN_PB_PIN) == PRESSED) // pushbutton is pressed - process_pushbutton(); - if (BOOTSEL) // boot selector button is pressed on Pico - process_bootsel(); + delayMicroseconds(100); } }