import machine
import time
import random
pins = [6, 7, 8, 9, 10, 11, 12, 13, 14, 15]
leds = []
for p in pins:
leds.append(machine.Pin(p, machine.Pin.OUT))
R = machine.Pin(2, machine.Pin.OUT)
G = machine.Pin(3, machine.Pin.OUT)
B = machine.Pin(4, machine.Pin.OUT)
def all_off():
for led in leds:
led.value(0)
def rgb_off():
R.value(0)
G.value(0)
B.value(0)
def set_color(r, g, b):
R.value(r)
G.value(g)
B.value(b)
def pattern1():
all_off()
for led in leds:
led.value(1)
set_color(1, 0, 0)
def pattern2():
all_off()
for i in range(10):
leds[i].value(i % 2)
set_color(0, 1, 0)
def pattern3():
all_off()
set_color(0, 0, 1)
for i in range(5):
leds[4 - i].value(1)
leds[5 + i].value(1)
time.sleep(0.3)
def pattern4():
all_off()
set_color(1, 1, 0)
for _ in range(30):
idx = random.randint(0, 5)
leds[idx].value(random.randint(0, 1))
time.sleep(0.05)
all_off()
def pattern6():
all_off()
set_color(0, 1, 1)
for i in range(10):
all_off()
leds[i].value(1)
time.sleep(0.05)
for i in range(8, -1, -1):
all_off()
leds[i].value(1)
time.sleep(0.05)
all_off()
print("= Running all patterns automatically =")
pattern1()
time.sleep(2)
pattern2()
time.sleep(2)
pattern3()
time.sleep(2)
pattern4()
time.sleep(2)
pattern6()
time.sleep(2)
all_off()
rgb_off()
while True:
all_off()
rgb_off()
print("= LED Patterns Program =")
print("\nChoose a Pattern:")
print("1 - All LEDs ON")
print("2 - Alternating LEDs")
print("3 - Center Out Pattern")
print("4 - Random LEDs")
print("5 - Running Light")
print("0 - Exit")
choice = input("Enter Choice: ")
if choice == "1":
pattern1()
elif choice == "2":
pattern2()
elif choice == "3":
pattern3()
elif choice == "4":
pattern4()
elif choice == "5":
pattern6()
elif choice == "0":
all_off()
rgb_off()
print("All OFF. Goodbye!")
break
else:
print("Invalid choice, try again")
continue
time.sleep(2)