generated from BrianPugh/python-template
-
-
Notifications
You must be signed in to change notification settings - Fork 12
/
main.py
42 lines (31 loc) · 1 KB
/
main.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
import argparse
import time
import belay
parser = argparse.ArgumentParser()
parser.add_argument("--port", "-p", default="/dev/ttyUSB0")
args = parser.parse_args()
# Setup the connection with the micropython board.
# This also executes a few common imports on-device.
device = belay.Device(args.port)
@device.setup
def setup(): # The function name doesn't matter, but is "setup" by convention.
from machine import Pin
led = Pin(25, Pin.OUT)
# This sends the function's code over to the board.
# Calling the local ``set_led`` function will
# execute it on-device.
@device.task
def set_led(state):
# Configuration for a Pi Pico board.
print(f"Printing from device; turning LED to {state}.")
led.value(state)
setup()
while True:
set_led(True) # Preferred way of executing function.
time.sleep(0.5)
device.task.set_led(False) # Also equally good.
time.sleep(0.5)
device("set_led(True)") # Also works, but is uglier.
time.sleep(0.5)
set_led(False)
time.sleep(0.5)