Chapter 6 code
This commit is contained in:
+6
-4
@@ -1,8 +1,10 @@
|
||||
"""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
|
||||
@@ -12,17 +14,17 @@ pio_input = """
|
||||
|
||||
assembled = adafruit_pioasm.assemble(pio_input)
|
||||
|
||||
## set up a statemachine
|
||||
sm = rp2pio.StateMachine(
|
||||
assembled,
|
||||
frequency=2000,
|
||||
first_in_pin=board.GP20
|
||||
)
|
||||
|
||||
buffer = bytearray(1) # an array of bytes to read into - we are just asking for a byte
|
||||
buffer = array.array('I', [0])
|
||||
|
||||
while True:
|
||||
# read data from the fifo
|
||||
data = sm.readinto(buffer)
|
||||
sm.readinto(buffer)
|
||||
# print it.
|
||||
print("{:08b}".format(buffer[0]))
|
||||
print(f"{buffer[0]:032b}")
|
||||
time.sleep(0.1)
|
||||
+2
-1
@@ -3,6 +3,7 @@ Then turn the wheel slowly to see the change"""
|
||||
import board
|
||||
import rp2pio
|
||||
import adafruit_pioasm
|
||||
import array
|
||||
|
||||
pio_input = """
|
||||
.program pio_input
|
||||
@@ -24,6 +25,6 @@ buffer = bytearray(1) # an array of bytes to read into - we are just asking for
|
||||
|
||||
while True:
|
||||
# read data from the fifo
|
||||
data = sm.readinto(buffer)
|
||||
sm.readinto(buffer)
|
||||
# print it.
|
||||
print("{:08b}".format(buffer[0]))
|
||||
Reference in New Issue
Block a user