""" LED RGB. Colors aleatoris """
from machine import Pin, PWM
from random import randint # permet obtenir nombres enters aleatoris
from time import sleep
R = PWM (Pin(23), 5000)
G = PWM (Pin(22), 5000)
B = PWM (Pin(21), 5000)
# Cal aplicar un factor de proporcionalitat per canviar del rang de colors (0 a 255) al rang de duty (0 a 1023):
fp = int(1023/255) # el resultat de la operació és decimal. int retornarà nombre enter
while True:
# randint() genera un nombre enter aleatori dins el rang definit
R.duty (randint(0,255)*fp)
G.duty (randint(0,255)*fp)
B.duty (randint(0,255)*fp)
sleep (0.1)