code.py
 1  # SPDX-FileCopyrightText: 2018 Kattni Rembor for Adafruit Industries
 2  #
 3  # SPDX-License-Identifier: MIT
 4  
 5  import time
 6  
 7  import board
 8  import pwmio
 9  
10  piezo = pwmio.PWMOut(board.A2, duty_cycle=0,
11                         frequency=440, variable_frequency=True)
12  
13  while True:
14      for f in (262, 294, 330, 349, 392, 440, 494, 523):
15          piezo.frequency = f
16          piezo.duty_cycle = 65536 // 2  # On 50%
17          time.sleep(0.25)  # On for 1/4 second
18          piezo.duty_cycle = 0  # Off
19          time.sleep(0.05)  # Pause between notes
20      time.sleep(0.5)