Merge pull request #71 from kattni/circuitpython-quick-start

adding PWM piezo examples
This commit is contained in:
Kattni 2018-03-08 20:13:59 -05:00 committed by GitHub
commit f96270e883
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 23 additions and 0 deletions

View file

@ -0,0 +1,14 @@
import pulseio
import time
import board
piezo = pulseio.PWMOut(board.A2, duty_cycle=0, frequency=440, variable_frequency=True)
while True:
for f in (262, 294, 330, 349, 392, 440, 494, 523):
piezo.frequency = f
piezo.duty_cycle = 65536 // 2 # On 50%
time.sleep(0.25) # On for 1/4 second
piezo.duty_cycle = 0 # Off
time.sleep(0.05) # Pause between notes
time.sleep(0.5)

View file

@ -0,0 +1,9 @@
import time
import board
import simpleio
while True:
for f in (262, 294, 330, 349, 392, 440, 494, 523):
simpleio.tone(board.A2, f, 0.25) # on for 1/4 second
time.sleep(0.05) # pause between notes
time.sleep(0.5)