diff options
author | Jonas Smedegaard <dr@jones.dk> | 2023-10-12 14:24:50 +0200 |
---|---|---|
committer | Jonas Smedegaard <dr@jones.dk> | 2023-10-12 14:24:50 +0200 |
commit | d5d731072c0679acee2593cf909acfe6775f3417 (patch) | |
tree | 15d1b6417dfd58f2d37b44b2d93331763e879ac9 | |
parent | 9f8551b0f2be8295f28cc65eb2a7322b9adffa64 (diff) |
prepare for pooling multiple pill reqests (when servo is async)
-rw-r--r-- | main.ino | 8 |
1 files changed, 4 insertions, 4 deletions
@@ -85,7 +85,7 @@ ServoEasing servo; #define SERVO_POS_INIT 0 #define SERVO_POS_MAX 90 -int servo_should_move = 0; +volatile int pills_requested = 0; void setup() { Serial.begin(BAUDRATE); @@ -173,7 +173,7 @@ IRAM_ATTR // avoid crash e.g. when other code reads SD card void onButtonActionPressed() { Serial.println("button ACTION clicked"); led.fastBlinking(); - servo_should_move = 1; + pills_requested++; rolling_green(); } @@ -212,10 +212,10 @@ void printData() { // source: https://robojax.com/learn/arduino/?vid=robojax_Servo_PB1_move_return void servoLoop() { - if (servo_should_move == 1) { + if (pills_requested > 1) { servo.easeTo(SERVO_POS_MAX); delay(500); servo.easeTo(SERVO_POS_INIT); - servo_should_move = 0; + pills_requested--; } } |