PWM LED fade out and timing with Coin Chime working

This commit is contained in:
Mikey Sklar 2018-09-04 13:26:52 -06:00
parent 376951bded
commit c87c47e219
2 changed files with 24 additions and 5 deletions

View file

@ -1,9 +1,28 @@
import time
import board
import simpleio
import pulseio
while True:
for f in (262, 294, 330, 349, 392, 440, 494, 523):
simpleio.tone(board.D2, f, 0.25) # on for 1/4 second
time.sleep(0.05) # pause between notes
time.sleep(0.5)
# PWM is not available on Trinket D1
speaker_pin = board.D2 # PWM speaker using simpleio interface on D2
pwm_leds = board.D4 # PWM (fading) LEDs are connected on D0
pwm = pulseio.PWMOut(pwm_leds, frequency=256, duty_cycle=50)
# wait for vibration sensor detect
# LEDs start high and fade down
brightness = 2 ** 15
fade_amount = 2 ** 13
# Super Mario Bros. Coin Sound with LED fade out
pwm.duty_cycle = brightness
time.sleep(.15)
simpleio.tone(speaker_pin, 988, 0.083) # tone1 - B5
brightness -= fade_amount
pwm.duty_cycle = brightness
simpleio.tone(speaker_pin, 1319, 0.83) # tone2 - E6
time.sleep(.15)
brightness -= fade_amount
pwm.duty_cycle = brightness
time.sleep(.15)
pwm.duty_cycle = 0