20.05.2021, 08:51
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