mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-19 06:03:57 +00:00
buzzer: no tone during rest
This commit is contained in:
committed by
Ron Evans
parent
d27859453c
commit
ea944c8933
@@ -54,6 +54,12 @@ func (l *Device) Tone(hz, duration float64) (err error) {
|
|||||||
|
|
||||||
tempo := ((60 / l.BPM) * (duration * 1000))
|
tempo := ((60 / l.BPM) * (duration * 1000))
|
||||||
|
|
||||||
|
// no tone during rest, just let the duration pass.
|
||||||
|
if hz == Rest {
|
||||||
|
time.Sleep(time.Duration(tempo) * time.Millisecond)
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
for i := 0.0; i < tempo*1000; i += tone * 2.0 {
|
for i := 0.0; i < tempo*1000; i += tone * 2.0 {
|
||||||
if err = l.On(); err != nil {
|
if err = l.On(); err != nil {
|
||||||
return
|
return
|
||||||
|
|||||||
Reference in New Issue
Block a user