April 2020
Intermediate to advanced
294 pages
7h 53m
English
We are using LEDs to simulate the control of physical mechanisms that we may want to control with our sensor node. In order to control the LEDs, we need to assign several GPIO pins to the LEDs and create a few simple functions to command them, such as gpio_on and gpio_off. We can create a few LED objects using the following code:
LED1 = machine.Pin(2, machine.Pin.OUT)LED2 = machine.Pin(0, machine.Pin.OUT)LED3 = machine.Pin(4, machine.Pin.OUT)
As you can see, we use machine to generically assign the specific pins that we will be using and to set the output mode. With the pins assigned, we can then write a few helper functions to control the LEDs, such as the following:
def gpio_toggle(p): p.value(not p.value())def gpio_on(p): ...
Read now
Unlock full access