adafruit / Adafruit_CircuitPython_seesaw

seesaw helper IC driver for circuitPython
MIT License
62 stars 36 forks source link

Variable Frequency PWM for ATtiny8x7 Seesaw Breakout #89

Open rsbohn opened 2 years ago

rsbohn commented 2 years ago

I want to make a variety of beep noises with the ATtiny8x7 Seesaw Breakout. The PWMOut object suggests that changing the frequency is possible, but in practice it is not.

def sweep_down(high: int, low:int):
    spkr.frequency = high
    spkr.duty_cycle = 0x8000
    decay = 0.9
    while spkr.frequency > low:
        spkr.frequency = int(spkr.frequency * decay)
    spkr.duty_cycle = 0

sweep_down(2000,80)

This proposed code would make a sound that starts at 2000 Hz and drops to around 80 Hz, then silence.

Equipment: I'm using Adafruit CircuitPython 7.0.0 on 2021-09-20; Raspberry Pi Pico with rp2040 to drive the ATtiny817 Seesaw Breakout board, with a speaker on pin 13.

It makes a sound but the frequency does not change.