Created
October 31, 2025 19:02
-
-
Save twisted-nematic57/d886fac2e6b04d4068c3d8710d84ca6b to your computer and use it in GitHub Desktop.
hallowen candle made in 1hr
This file contains hidden or 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
| # CANDLE v0.1.0 | |
| # Contributors to this file: | |
| # - twisted_nematic57 | |
| # This file is Public Domain | |
| import machine | |
| import rp2 | |
| import sys # I don't know why this is needed | |
| import _thread | |
| from time import * # why not `import time`? we'll never know | |
| import random | |
| print("CANDLE INIT: boot") # I cant believe I just wrote a f****** candle at 12 in the night | |
| machine.freq(125 * 1000 * 1000) # Initial low clock due to wireless chip-connected power indicator shenanigans | |
| led = machine.Pin("LED",machine.Pin.OUT) | |
| led.on() # Power indicator | |
| machine.freq(280 * 1000 * 1000) # Now that the wireless chip is out of the way... | |
| print("I AM SPEED") | |
| gpio_red = 14 # Modify these if needed. | |
| gpio_yel = 16 # Any GPIO should work on the RP2040. | |
| red = machine.PWM(gpio_red,freq=1024,duty_u16=65535) | |
| def core1(): # Core 1 handles the yellow LED | |
| yel = machine.PWM(gpio_yel,freq=1024,duty_u16=65535) | |
| while True: | |
| y_oldfreq = yel.duty_u16() | |
| y_newfreq = random.randint(2048,65535) # anything below 2048 sure as heck aint gonna be visible in broad daylight | |
| if y_newfreq > y_oldfreq: # please excuse this very quickly hacked together memory inefficient sh**, i know this could've been done better. | |
| for i in range(y_oldfreq,y_newfreq,random.randint(1,3)): # [1,3] chosen specifically because 1 is pretty slow && 4 is too fast to be believable | |
| yel.duty_u16(i) # the RP2040 core is slow enough such that there is no sleeping needed to make the fading speed realistic. | |
| else: | |
| for i in range(y_oldfreq,y_newfreq,-random.randint(1,3)): | |
| yel.duty_u16(i) | |
| sleep_ms(random.randint(20,200)) # (inter-fade delays) | |
| yel_thread = _thread.start_new_thread(core1,()) # I paid for the whole chip so I'm gonna use the whole damn chip | |
| print("Yellow LED initialized, now starting red LED...") | |
| while True: # Core 0 activities (red LED) | |
| r_oldfreq = red.duty_u16() # now do the same for red | |
| r_newfreq = random.randint(2048,65535) | |
| if r_newfreq > r_oldfreq: | |
| for i in range(r_oldfreq,r_newfreq,random.randint(1,3)): | |
| red.duty_u16(i) | |
| else: | |
| for i in range(r_oldfreq,r_newfreq,-random.randint(1,3)): | |
| red.duty_u16(i) | |
| sleep_ms(random.randint(20,200)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment