Untitled
unknown
plain_text
a year ago
895 B
8
Indexable
import board, pwmio, time
from adafruit_motor import servo
pwm = pwmio.PWMOut(board.GP16, frequency = 50)
servo_1 = servo.Servo(pwm, min_pulse = 580, max_pulse = 2530)
servo_1.angle = 180
time.sleep(2.0)
servo_1.angle = 90
time.sleep(2.0)
servo_1.angle = 0
time.sleep(2.0)
tone = pwmio.PWMOut(board.GP0, variable_frequency=True)
volume = 42768
tone.duty_cycle = volume
notes = [900, 440, 1200]
tone_duration = 0.2
rest_duration = 0.01 # Corrected line
long_rest_duration = 2.0
def play_a_tone(freq, duration):
tone.duty_cycle = volume
tone.frequency = freq
time.sleep(duration)
def play_a_rest(duration):
tone.duty_cycle = 0
time.sleep(duration)
while True:
for note in notes:
play_a_tone(note, tone_duration)
play_a_rest(rest_duration)
play_a_rest(long_rest_duration)Editor is loading...
Leave a Comment