from machine import Pin, PWM, ADC
import time
xAxis = ADC(Pin(27))
pot = ADC(Pin(26))
button = Pin(16,Pin.IN, Pin.PULL_UP)
rled = PWM(Pin(19))
gled = PWM(Pin(20))
bled = PWM(Pin(21))
min_angle = 2000
max_angle = 7600
max_brightness = 1023
rled.freq(500)
gled.freq(500)
bled.freq(500)
while True:
xValue = xAxis.read_u16()
potValue = pot.read_u16()
buttonValue = button.value()
xStatus = "middle"
buttonStatus = "not pressed"
xangle = int(((xValue - 0) / (65535 - 0)) * (max_angle - min_angle) + min_angle)
if xValue <= 0:
xStatus = "right"
bled.duty_u16(int(max_brightness * potValue / 65535))
rled.duty_u16(0)
gled.duty_u16(0)
elif xValue >= 60000:
xStatus = "left"
rled.duty_u16(int(max_brightness * potValue / 65535))
gled.duty_u16(0)
bled.duty_u16(0)
else:
gled.duty_u16(int(max_brightness * potValue / 65535))
rled.duty_u16(0)
bled.duty_u16(0)
xStatus = "middle"
#Hall Effect = 89 | Potentiometer = 0 | Voltage = 0.00
print("Hall Effect = " + str(xValue) + " | Potentiometer = " + str(potValue) + " | Voltage = " + str(potValue * 3.3 / 65535) + "v")