Skip to content

Commit d0a1c94

Browse files
committed
samples/agriculture: minor improvements in the button/led handling
Signed-off-by: Ruben Moral <[email protected]>
1 parent da95b65 commit d0a1c94

File tree

1 file changed

+7
-13
lines changed
  • samples/demos/end_to_end_agriculture

1 file changed

+7
-13
lines changed

samples/demos/end_to_end_agriculture/main.py

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -147,10 +147,6 @@
147147

148148
sensor = None
149149

150-
LED_PIN_ID = "D9"
151-
152-
led_pin = Pin(LED_PIN_ID, Pin.OUT, value=VALUE_DISABLED)
153-
154150

155151
def read_properties():
156152
"""
@@ -540,14 +536,10 @@ def toggle_valve():
540536
Toggles the status of the electronic valve.
541537
"""
542538
global valve_pos
543-
status = valve_pos
544539

545-
if status == 0:
546-
valve_pos = True
547-
else:
548-
valve_pos = False
549-
550-
print("- Toggling valve status to '{}'.".format("Open" if valve_pos == True else "Closed"))
540+
valve_pos = 1 if valve_pos == 0 else 0
541+
print("- Toggling valve status to '{}'.".format("Open" if valve_pos == 1 else "Closed"))
542+
# Turn on/off the LED.
551543
led_pin.value(valve_pos)
552544

553545

@@ -617,6 +609,9 @@ def main():
617609
except AssertionError:
618610
pass
619611

612+
# Simulate temperature if no I2C sensor is detected.
613+
simulate_temp = sensor is None
614+
620615
# Configure the Bluetooth advertisement.
621616
config_advertisement()
622617

@@ -633,8 +628,7 @@ def main():
633628
# Sleep 100 ms.
634629
time.sleep_ms(100)
635630

636-
# If the button has been pressed, swap the temperature source
637-
# (reading or simulation).
631+
# If the button has been pressed, toggle the electronic valve.
638632
if not was_btn_pressed and is_button_pressed():
639633
toggle_valve()
640634
status_response = {

0 commit comments

Comments
 (0)