[Tutor] Hi
Chidinma Ufomadu
fufomadu894 at gmail.com
Sat Apr 9 12:42:32 EDT 2022
I need help with a project. I can't seem to be able to make the green led
come on when the servo is rotating, the red led just stay on. from machine
import Pin, PWM, ADC
import utime
Pot = ADC(0)# Pot at channel 0 for servo
servo = PWM(Pin(0)) # GPIO pins
servo.freq(50)
switch = (3, Pin.IN, Pin.PULL_UP) # PMW wave input
L1 = Pin(1, Pin.OUT) #GPIO2 set as pin for RED LED
L2 = Pin(2, Pin.OUT) #GPIO3 set as pin for Green LED
ch1 = PWM(Pin(2)) # set ch1 for L1 to PWM using GP2
ch1.freq(1000)
ch2 = PWM(Pin(3)) # set ch2 for L2 to PWM using GP3
ch2.freq(1000)
while True: # Do forever
duty = Pot.read_u16() # Copy pot Raw value to duty
value = int(1350 + (Pot.read_u16() / 9.57))
# adds the ruired offset to raw value of pot.
servo.duty_u16(value) # final value needed a bit of weaking
print(value)
utime.sleep(0.5)
L1.value(1)
L2.value(0)
utime.sleep(0.5)
That's the code I have written. I don't know what the problem is, please
help. Thank you.
More information about the Tutor
mailing list