import rp2
from machine import Pin
from rp2 import PIO
import time
@rp2.asm_pio(out_init=[PIO.OUT_LOW])
def echo():
wrap_target()
mov(pins, isr)
mov(isr, invert(isr))
pull(noblock)
mov(x, osr)
mov(y, x)
label("loop")
jmp(y_dec, "loop")
wrap()
sm = rp2.StateMachine(0, echo, freq=1_000_000, out_base=Pin(7))
sm.active(1)
def play(freq):
if freq:
sm.put(1_000_000//freq)
else:
sm.put(0)
play(500)
time.sleep(1)
play(1000)
time.sleep(1)
play(0)
from imu import MPU6050
from time import sleep
from machine import Pin, I2C
i2c = I2C(0, sda=Pin(0), scl=Pin(1))
imu = MPU6050(i2c)
while True:
ax=round(imu.accel.x,2)
ay=round(imu.accel.y,2)
az=round(imu.accel.z,2)
gx=round(imu.gyro.x)
gy=round(imu.gyro.y)
gz=round(imu.gyro.z)
tem=round(imu.temperature,2)
print("ax",ax,"\t","ay",ay,"\t","az",az,"\t","gx",gx,"\t","gy",gy,"\t","gz",gz,"\t","Temperature",tem," ",end="\r")
sleep(0.2)