from machine import Pin, PWM
import time
# posição dos pinos RGB
RED = 0
GREEN = 1
BLUE = 2
# pinos RGB selecionados
pwm_pins = [10, 11, 12]
pwm1 = PWM(Pin(pwm_pins[RED])) # create a PWM object on a pin and set freq and duty
pwm2 = PWM(Pin(pwm_pins[GREEN])) # create a PWM object on a pin and set freq and duty
pwm3 = PWM(Pin(pwm_pins[BLUE])) # create a PWM object on a pin and set freq and duty
def init_freq_pwm():
pwm1.freq(1000)
pwm2.freq(1000)
pwm3.freq(1000)
def deinit_pwm_pins():
pwms[RED].deinit()
pwms[GREEN].deinit()
pwms[BLUE].deinit()
# main function
def main():
print('pwm')
while True:
pwm1.duty_u16(32768) # set duty to 50%
pwm2.duty_u16(0) # set duty to 50%
pwm3.duty_u16(0) # set duty to 50%
time.sleep(1)
pwm1.duty_u16(0) # set duty to 50%
pwm2.duty_u16(32768) # set duty to 50%
pwm3.duty_u16(0) # set duty to 50%
time.sleep(1)
pwm1.duty_u16(0) # set duty to 50%
pwm2.duty_u16(0) # set duty to 50%
pwm3.duty_u16(32768) # set duty to 50%
time.sleep(1)
if __name__ == "__main__":
init_freq_pwm()
main()