Skip to content

Instantly share code, notes, and snippets.

@Crysknife007
Created July 23, 2022 19:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Crysknife007/dd174ddce585250a2a17d2189a452077 to your computer and use it in GitHub Desktop.
Save Crysknife007/dd174ddce585250a2a17d2189a452077 to your computer and use it in GitHub Desktop.
Firefly Simulator for Pi Pico in Circuit Python
# Pi Pico Firefly Simulator
# By Spike Snell 2022
# Import what we need to run the onboard led
import time, board, pwmio, random, microcontroller
# Create a pseudorandom frequency
freq = random.randint(2000,200000)
# Set up the onboard led
led = pwmio.PWMOut(board.LED, frequency=freq, duty_cycle=0)
# Loop 100 times
for i in range(100):
# Ramp the brightness up somewhat quickly
for b in range(6553):
# Set the led brightness
led.duty_cycle = b * 10
# Fade the led out more slowly
for f in range(65535):
# Set the led brightness
led.duty_cycle = 65535 - f
# Sleep for an amount of time between 3 to 14 seconds
time.sleep(random.randint(3,14))
# Reset the board to start emulate a new bug cycle
microcontroller.reset()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment