Untitled
unknown
plain_text
15 days ago
895 B
2
Indexable
Never
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)
Leave a Comment