from machine import Pin, ADC, PWM
from time import sleep
Red = Pin(12, Pin.OUT)
Green = Pin(14, Pin.OUT)
Blue = Pin(27, Pin.OUT)
R = PWM(Red, 500)
G = PWM(Green, 500)
B = PWM(Blue, 500)
# 500hz frequency
# Set duty cycle
# This function accept values between 0-65535
# 0 = 0% and 65535 = 100%
# This means each percentage is 65535 / 100 = 655.35
# For 50% it means 655.35 * 50% = 32767.5 rounded to 32768
R.duty_u16(0)
G.duty_u16(0)
B.duty_u16(0)
sleep(1)
red_pot = ADC(Pin(2, Pin.IN))
green_pot = ADC(Pin(0, Pin.IN))
blue_pot = ADC(Pin(4, Pin.IN))
# scale = (d-c) / (b-a) = 65535/4095 = 16 (approximately)
# no offset
while True:
red_value = red_pot.read()
green_value = green_pot.read()
blue_value = blue_pot.read()
scale = 16
R.duty_u16(red_value * scale)
G.duty_u16(green_value * scale)
B.duty_u16(blue_value * scale)
sleep(0.5)
# while True:
# R.duty_u16(32768)
# sleep(1)
# R.duty_u16(0)
# sleep(1)
# G.duty_u16(32768)
# sleep(1)
# G.duty_u16(0)
# sleep(1)
# B.duty_u16(32768)
# sleep(1)
# B.duty_u16(0)
# sleep(1)
# for i in range(0, 65535, 6553):
# dc = i if i > 6555 else 0
# R.duty_u16(dc)
# G.duty_u16(dc)
# B.duty_u16(dc)
# sleep(0.2)
# sleep(2)