# From: https://www.hackster.io/shilleh/connect-mpu-6050-to-raspberry-pi-pico-w-7f3345
# Shows Pi is on by turning on LED when plugged in
LED = machine.Pin("LED", machine.Pin.OUT)
LED.on()
from imu import MPU6050
from time import sleep
from machine import Pin, I2C
red = Pin(18, Pin.OUT)
green = Pin(17, Pin.OUT)
blue = Pin(16, Pin.OUT)
# i2c = I2C(1, sda=Pin(6), scl=Pin(7), freq=400000) # XIAO RP2040
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000) # Pico
imu = MPU6050(i2c)
print("Change the value of the X-axis Rotation")
while True:
gx=round(imu.gyro.x)
print("X-Axis",gx," ",end="\r")
sleep(0.2)
if(gx <= 30 and gx > 0):
red.value(1)
green.value(0)
blue.value(0)
elif(gx > 30 and gx <= 60 ):
green.value(1)
red.value(0)
blue.value(0)
elif(gx > 60 and gx <= 90):
blue.value(1)
red.value(0)
green.value(0)
elif(gx > 90):
blue.value(1)
red.value(1)
green.value(1)
else:
red.value(0)
green.value(0)
blue.value(0)