From 98d2a18c615dc7c252da605b463c1cd9bfb7d024 Mon Sep 17 00:00:00 2001 From: jimmy Date: Thu, 27 Jun 2024 20:17:07 -0500 Subject: [PATCH 1/1] twinkling purple/pink lights --- main.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ main0.py | 51 +++++++++++++++++++++++++++++++++++++++++++++++++++ main1.py | 48 ++++++++++++++++++++++++++++++++++++++++++++++++ main2.py | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 200 insertions(+) create mode 100644 main.py create mode 100644 main0.py create mode 100644 main1.py create mode 100644 main2.py diff --git a/main.py b/main.py new file mode 100644 index 0000000..7f72a1e --- /dev/null +++ b/main.py @@ -0,0 +1,51 @@ +# Imports +from machine import Pin +from neopixel import NeoPixel +import time, random + +# LED details +GPIOnumber = 28 +LEDcount = 15 + +# set up buttons +cBtn=Pin(16,Pin.IN,Pin.PULL_UP) +sBtn=Pin(17,Pin.IN,Pin.PULL_UP) + +# Define the strand pin number and number of LEDs from variables +strand = NeoPixel(Pin(GPIOnumber), LEDcount) + +global mycolour +mycolour=(78,0,45) +pink=(253,58,73) +# Turn off all LEDs before program start +strand.fill((mycolour)) +strand.write() +time.sleep(1) + +def ledStrand(): + i=random.randint(0,LEDcount-1) + strand[i]=(mycolour) + strand.write() + time.sleep(.09) + strand[i]=(pink) + strand.write() + time.sleep(1.09) + +def nColor(): + global mycolour + mycolour=(random.randint(0,255),random.randint(0,255),random.randint(0,255)) + time.sleep(0.09) + +def clearStrand(): + strand.fill((0,0,0)) + strand.write() + +while True: + ledStrand() + if sBtn.value()==0: + clearStrand() + break + if cBtn.value()==0: + nColor() + + diff --git a/main0.py b/main0.py new file mode 100644 index 0000000..7f72a1e --- /dev/null +++ b/main0.py @@ -0,0 +1,51 @@ +# Imports +from machine import Pin +from neopixel import NeoPixel +import time, random + +# LED details +GPIOnumber = 28 +LEDcount = 15 + +# set up buttons +cBtn=Pin(16,Pin.IN,Pin.PULL_UP) +sBtn=Pin(17,Pin.IN,Pin.PULL_UP) + +# Define the strand pin number and number of LEDs from variables +strand = NeoPixel(Pin(GPIOnumber), LEDcount) + +global mycolour +mycolour=(78,0,45) +pink=(253,58,73) +# Turn off all LEDs before program start +strand.fill((mycolour)) +strand.write() +time.sleep(1) + +def ledStrand(): + i=random.randint(0,LEDcount-1) + strand[i]=(mycolour) + strand.write() + time.sleep(.09) + strand[i]=(pink) + strand.write() + time.sleep(1.09) + +def nColor(): + global mycolour + mycolour=(random.randint(0,255),random.randint(0,255),random.randint(0,255)) + time.sleep(0.09) + +def clearStrand(): + strand.fill((0,0,0)) + strand.write() + +while True: + ledStrand() + if sBtn.value()==0: + clearStrand() + break + if cBtn.value()==0: + nColor() + + diff --git a/main1.py b/main1.py new file mode 100644 index 0000000..ec49221 --- /dev/null +++ b/main1.py @@ -0,0 +1,48 @@ +# Imports +from machine import Pin +from neopixel import NeoPixel +import time, random + +# LED details +GPIOnumber = 28 +LEDcount = 15 + +# set up buttons +cBtn=Pin(16,Pin.IN,Pin.PULL_UP) +sBtn=Pin(17,Pin.IN,Pin.PULL_UP) + +# Define the strand pin number and number of LEDs from variables +strand = NeoPixel(Pin(GPIOnumber), LEDcount) + +global mycolour +mycolour=(78,0,45) +# Turn off all LEDs before program start +strand.fill((mycolour)) +strand.write() +time.sleep(1) + +def ledStrand(): + i=random.randint(0,LEDcount-1) + strand[i]=(0,0,0) + strand.write() + time.sleep(0.09) + strand[i]=(mycolour) + strand.write() + time.sleep(0.09) + +def nColor(): + global mycolour + mycolour=(random.randint(0,255),random.randint(0,255),random.randint(0,255)) + time.sleep(0.09) + +def clearStrand(): + strand.fill((0,0,0)) + strand.write() + +while True: + ledStrand() + if sBtn.value()==0: + clearStrand() + break + if cBtn.value()==0: + nColor() diff --git a/main2.py b/main2.py new file mode 100644 index 0000000..5df92b7 --- /dev/null +++ b/main2.py @@ -0,0 +1,50 @@ +# Imports +from machine import Pin +from neopixel import NeoPixel +import time, random + +# LED details +GPIOnumber = 28 +LEDcount = 15 + +# set up buttons +cBtn=Pin(16,Pin.IN,Pin.PULL_UP) +sBtn=Pin(17,Pin.IN,Pin.PULL_UP) + +# Define the strand pin number and number of LEDs from variables +strand = NeoPixel(Pin(GPIOnumber), LEDcount) + +global mycolour +mycolour=(78,0,45) +pink=(253,58,73) +# Turn off all LEDs before program start +strand.fill((mycolour)) +strand.write() +time.sleep(1) + +def ledStrand(): + i=random.randint(0,LEDcount-1) + strand[i]=(mycolour) + strand.write() + time.sleep(0.09) + strand[i]=(pink) + strand.write() + time.sleep(0.09) + +def nColor(): + global mycolour + mycolour=(random.randint(0,255),random.randint(0,255),random.randint(0,255)) + time.sleep(0.09) + +def clearStrand(): + strand.fill((0,0,0)) + strand.write() + +while True: + ledStrand() + if sBtn.value()==0: + clearStrand() + break + if cBtn.value()==0: + nColor() + -- 2.47.3