20.05.2021, 08:58
(20.05.2021, 08:51)admin Wrote: Buzzer control for new HW (with volume control):
Code:function beep(note, time, volume)
volume = volume or 10
volume = 1 + (11 - volume) ^ 2
local period = math.floor(10 ^ 9 / note)
local cycle = math.floor(period / volume)
local path = '/sys/class/pwm/pwmchip3/pwm0/'
io.writefile(path .. 'period', period)
io.writefile(path .. 'duty_cycle', cycle)
io.writefile(path .. 'enable', 1)
os.sleep(time or 0.1)
io.writefile(path .. 'enable', 0)
end
Thanks it works, and how lower the volume value, how harder the buzzer?
And is it correct that this device doesn't display a pm25 value?