Created
July 23, 2022 19:49
-
-
Save Crysknife007/dd174ddce585250a2a17d2189a452077 to your computer and use it in GitHub Desktop.
Firefly Simulator for Pi Pico in Circuit Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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