Files
Robotics-at-Home-with-Raspb…/ch-6/1-simple-input/pio_read_1_pin.py
T
Danny Staple 881355daaa Chapter 6 code
2022-01-28 21:10:14 +00:00

31 lines
605 B
Python

"""Send this code, run and watch the repl.
Then turn the wheel slowly to see the change"""
import time
import board
import rp2pio
import adafruit_pioasm
import array
pio_input = """
.program pio_input
in pins, 1 ; read in pin (into ISR)
push noblock ; put this into input FIFO
"""
assembled = adafruit_pioasm.assemble(pio_input)
sm = rp2pio.StateMachine(
assembled,
frequency=2000,
first_in_pin=board.GP20
)
buffer = array.array('I', [0])
while True:
# read data from the fifo
sm.readinto(buffer)
# print it.
print(f"{buffer[0]:032b}")
time.sleep(0.1)