File tree Expand file tree Collapse file tree 1 file changed +7
-13
lines changed
samples/demos/end_to_end_agriculture Expand file tree Collapse file tree 1 file changed +7
-13
lines changed Original file line number Diff line number Diff line change 147
147
148
148
sensor = None
149
149
150
- LED_PIN_ID = "D9"
151
-
152
- led_pin = Pin (LED_PIN_ID , Pin .OUT , value = VALUE_DISABLED )
153
-
154
150
155
151
def read_properties ():
156
152
"""
@@ -540,14 +536,10 @@ def toggle_valve():
540
536
Toggles the status of the electronic valve.
541
537
"""
542
538
global valve_pos
543
- status = valve_pos
544
539
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.
551
543
led_pin .value (valve_pos )
552
544
553
545
@@ -617,6 +609,9 @@ def main():
617
609
except AssertionError :
618
610
pass
619
611
612
+ # Simulate temperature if no I2C sensor is detected.
613
+ simulate_temp = sensor is None
614
+
620
615
# Configure the Bluetooth advertisement.
621
616
config_advertisement ()
622
617
@@ -633,8 +628,7 @@ def main():
633
628
# Sleep 100 ms.
634
629
time .sleep_ms (100 )
635
630
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.
638
632
if not was_btn_pressed and is_button_pressed ():
639
633
toggle_valve ()
640
634
status_response = {
You can’t perform that action at this time.
0 commit comments