47 lines
908 B
Go
47 lines
908 B
Go
|
|
package main
|
||
|
|
|
||
|
|
import (
|
||
|
|
"machine"
|
||
|
|
"time"
|
||
|
|
)
|
||
|
|
|
||
|
|
var bzrPin machine.Pin
|
||
|
|
var btnA, btnB, btnRot machine.Pin
|
||
|
|
|
||
|
|
func main() {
|
||
|
|
|
||
|
|
// buttons: active LOW (internal pull-up)
|
||
|
|
btnA = machine.P1_06
|
||
|
|
btnB = machine.P1_04
|
||
|
|
btnRot = machine.P0_22 // rotary encoder push button
|
||
|
|
btnA.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
|
||
|
|
btnB.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
|
||
|
|
btnRot.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
|
||
|
|
|
||
|
|
// passive buzzer on P0_31
|
||
|
|
bzrPin = machine.P0_31
|
||
|
|
bzrPin.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||
|
|
|
||
|
|
for {
|
||
|
|
if !btnA.Get() {
|
||
|
|
tone(1046) // C6
|
||
|
|
}
|
||
|
|
if !btnB.Get() {
|
||
|
|
tone(739) // F#5
|
||
|
|
}
|
||
|
|
if !btnRot.Get() {
|
||
|
|
tone(523) // C5
|
||
|
|
}
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
func tone(freq int) {
|
||
|
|
for i := 0; i < 10; i++ {
|
||
|
|
bzrPin.High()
|
||
|
|
time.Sleep(time.Duration(freq) * time.Microsecond)
|
||
|
|
|
||
|
|
bzrPin.Low()
|
||
|
|
time.Sleep(time.Duration(freq) * time.Microsecond)
|
||
|
|
}
|
||
|
|
}
|