Skip to content

Instantly share code, notes, and snippets.

@fxprime
Created September 23, 2023 14:19
Show Gist options
  • Save fxprime/4921efc783b662a25adbcd35fea33e85 to your computer and use it in GitHub Desktop.
Save fxprime/4921efc783b662a25adbcd35fea33e85 to your computer and use it in GitHub Desktop.
from machine import Pin, Timer
from time import sleep
import time
from neopixel import Neopixel # neopixel lib = https://github.com/blaz-r/pi_pico_neopixel/blob/main/neopixel.py
LED_PIN = 25
USRBUTTON_PIN = 24
NEOPIXEL_PIN = 23
led = Pin(LED_PIN, Pin.OUT)
timer = Timer()
pixels = Neopixel(1, 0, NEOPIXEL_PIN, "RGB")
def blink(timer):
led.toggle()
def wheel(pos):
if pos<0 or pos>255:
return (0,0,0)
if pos<85:
return (255-pos*3,pos*3,0)
if pos<170:
pos -= 85
return (0, 255-pos*3,pos*3)
pos -= 170
return (pos*3,0,255-pos*3)
timer.init(freq=2.5, mode=Timer.PERIODIC, callback=blink)
button = Pin(USRBUTTON_PIN, Pin.IN, Pin.PULL_UP)
pixels.brightness(50)
j=0
while True:
pixels.set_pixel(0, wheel(j))
pixels.show()
j=(j+1)%256
time.sleep(0.01)
if not button.value():
print ("Pressing")
time.sleep(0.5)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment