def main(addon): badge.show_bitmap('drivers/assets/speaker.bmp') audio = PWMOut(board.GPIO1, duty_cycle=0, frequency=440, variable_frequency=True) led = digitalio.DigitalInOut(board.GPIO2) led.switch_to_output(True) try: for (notename, eigths) in sequence: length = eigths * 0.1 if notename: led.value = False audio.frequency = round(note(notename)) audio.duty_cycle = 0x8000 time.sleep(length) led.value = True audio.duty_cycle = 0 time.sleep(0.025) time.sleep(3) finally: led.deinit() audio.deinit()
import neopixel from digitalio import DigitalInOut, Direction, Pull from analogio import AnalogIn from pulseio import PWMOut import audioio import touchio import simpleio import random # One pixel connected internally! dot = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.08) # pizeo buzzer buzzer = PWMOut(board.D5, variable_frequency=True) buzzer.frequency = 262 OFF = 0 ON = 2**15 # Digital input with pullup on D2, D3, D4, D5, D6 buttons = [] for p in [board.D6, board.D9, board.D10, board.A3, board.A4]: button = DigitalInOut(p) button.direction = Direction.INPUT button.pull = Pull.UP buttons.append(button) # Digital output on D8, D9, D10, D11, D12 buttonLeds = [] for p in [board.D11, board.D12, board.D13, board.A1, board.A2]:
import time import neopixel from digitalio import DigitalInOut, Direction, Pull from analogio import AnalogIn from pulseio import PWMOut import audioio import touchio import simpleio import random # One pixel connected internally! dot = neopixel.NeoPixel(board.NEOPIXEL, 1, brightness=0.08) # pizeo buzzer buzzer = PWMOut(board.D5, variable_frequency=True) buzzer.frequency = 262 OFF = 0 ON = 2**15 # Digital input with pullup on D2, D3, D4, D5, D6 buttons = [] for p in [board.D6, board.D9, board.D10, board.A3, board.A4]: button = DigitalInOut(p) button.direction = Direction.INPUT button.pull = Pull.UP buttons.append(button) # Digital output on D8, D9, D10, D11, D12 buttonLeds = [] for p in [board.D11, board.D12, board.D13, board.A1, board.A2]: buttonLed = DigitalInOut(p)
''' #导入相关模块 import board from pulseio import PWMOut import time #PWM构建,蜂鸣器引脚A4. frequency值必须大于3,否则报错 PWM = PWMOut(board.A4, duty_cycle=32768, frequency=200, variable_frequency=True) #循环发出不同频率响声。 while True: PWM.frequency = 200 time.sleep(1) PWM.frequency = 400 time.sleep(1) PWM.frequency = 600 time.sleep(1) PWM.frequency = 800 time.sleep(1) PWM.frequency = 1000 time.sleep(1)