EasyManuals Logo

Adafruit Feather M4 Express User Manual

Adafruit Feather M4 Express
178 pages
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Page #115 background imageLoading...
Page #115 background image
To use with the Metro M4 Express, ItsyBitsy M4 Express or the Feather M4 Express, you must comment out the
piezo = pulseio.PWMOut(board.A2, duty_cycle=0, frequency=440, variable_frequency=True) line and uncomment
the piezo = pulseio.PWMOut(board.A1, duty_cycle=0, frequency=440, variable_frequency=True) line. A2 is not a
supported PWM pin on the M4 boards!
If you have simpleio library loaded into your /lib folder on your board, we have a nice little helper that makes a tone
for you on a piezo with a single command.
To use with any of the M0 boards, no changes to the following code are needed.
To use with the Metro M4 Express, ItsyBitsy M4 Express or the Feather M4 Express, you must comment out the
simpleio.tone(board.A2, f, 0.25) line and uncomment the simpleio.tone(board.A1, f, 0.25) line. A2 is not a
supported PWM pin on the M4 boards!
As you can see, it's much simpler!
Remember: To "comment out" a line, put a # and a space before it. To "uncomment" a line, remove the # +
space from the beginning of the line.
import time
import board
import pulseio
# For the M0 boards:
piezo = pulseio.PWMOut(board.A2, duty_cycle=0, frequency=440, variable_frequency=True)
# For the M4 boards:
# piezo = pulseio.PWMOut(board.A1, 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)
import time
import board
import simpleio
while True:
for f in (262, 294, 330, 349, 392, 440, 494, 523):
# For the M0 boards:
simpleio.tone(board.A2, f, 0.25) # on for 1/4 second
# For the M4 boards:
# simpleio.tone(board.A1, f, 0.25) # on for 1/4 second
time.sleep(0.05) # pause between notes
time.sleep(0.5)
© Adafruit Industries https://learn.adafruit.com/adafruit-feather-m4-express-atsamd51 Page 120 of 183

Table of Contents

Questions and Answers:

Question and Answer IconNeed help?

Do you have a question about the Adafruit Feather M4 Express and is the answer not in the manual?

Adafruit Feather M4 Express Specifications

General IconGeneral
BrandAdafruit
ModelFeather M4 Express
CategoryMicrocontrollers
LanguageEnglish

Related product manuals