Created
December 24, 2023 17:20
-
-
Save seanburlington/582e16444659e67165eb1a7101ef1e74 to your computer and use it in GitHub Desktop.
an alternative programe for https://thepihut.com/blogs/raspberry-pi-tutorials/let-it-glow-maker-advent-calendar-day-4-brilliant-bar-graphs
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
from machine import Pin, PWM | |
import time | |
# Set up LED pins | |
seg1 = Pin(13, Pin.OUT) | |
seg2 = Pin(12, Pin.OUT) | |
seg3 = Pin(11, Pin.OUT) | |
seg4 = Pin(10, Pin.OUT) | |
seg5 = Pin(9, Pin.OUT) | |
duty_cycle = 100 | |
# Create a list of our LEDs | |
segments = [PWM(seg1), PWM(seg2), PWM(seg3), PWM(seg4), PWM(seg5)] | |
frequency = 5000 | |
for led in segments: | |
led.freq (frequency) | |
power = [ | |
[65536, 1400, 0, 0, 0], | |
[1400, 65536, 0, 0, 0], | |
[400, 1400, 65536, 0, 0], | |
[0, 400, 1400, 65536, 0], | |
[0, 0, 400, 1400, 65536], | |
[0, 0, 0, 65536, 1400], | |
[0, 0, 65536, 1400, 400], | |
[0, 65536, 1400, 400, 0], | |
[65536, 1400, 400, 0, 0], | |
] | |
pause=0.2 | |
try: | |
while True: | |
for seq in power: | |
for i in range(5): | |
segments[i].duty_u16(seq[i]) | |
time.sleep(pause) | |
except KeyboardInterrupt: | |
print("Keyboard interrupt") | |
for led in segments: | |
led.duty_u16(0) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment