So i have started to play with the pi pico w and using them to light up some of my lego sets. this is the first time doing this, so i'm very new to coding in Python. i have all a total of 11 lights i would like to light up, and then randomly dim one off and then back on while it is on. the lights are connected to pins 21,22,24,25,26,27,29,30,31,32,34. i have been looking online to see how i can randomize within the array of pins, but i have not been able to find what i'm looking for. i have found this bit of code from the website Random Nerds Tutorial:
# Complete project details at https://RandomNerdTutorials.com/raspberry-pi-pico-pwm-micropython/
from machine import Pin, PWM
from time import sleep
# Set up PWM Pin
led = machine.Pin(20)
led_pwm = PWM(led)
duty_step = 129 # Step size for changing the duty cycle
#Set PWM frequency
frequency = 5000
led_pwm.freq (frequency)
try:
while True:
# Increase the duty cycle gradually
for duty_cycle in range(0, 65536, duty_step):
led_pwm.duty_u16(duty_cycle)
sleep(0.005)
# Decrease the duty cycle gradually
for duty_cycle in range(65536, 0, -duty_step):
led_pwm.duty_u16(duty_cycle)
sleep(0.005)
i figure if i can get all the pins on at first, then switch the Increase and Decrease that would dim a light randomly. but then to run this on a random pin within a range of pins i have no idea. any help would be great