mirror of
https://github.com/tinygo-org/drivers.git
synced 2026-08-07 16:33:39 +00:00
makeybutton: add driver for MakeyMakey-like button
Signed-off-by: deadprogram <ron@hybridgroup.com>
This commit is contained in:
committed by
Daniel Esteban
parent
13c43350a3
commit
cafe8df620
@@ -0,0 +1,30 @@
|
||||
package main
|
||||
|
||||
import (
|
||||
"machine"
|
||||
"time"
|
||||
|
||||
"tinygo.org/x/drivers/makeybutton"
|
||||
)
|
||||
|
||||
var (
|
||||
led machine.Pin = machine.LED
|
||||
button machine.Pin = machine.BUTTON
|
||||
key *makeybutton.Button
|
||||
)
|
||||
|
||||
func main() {
|
||||
led.Configure(machine.PinConfig{Mode: machine.PinOutput})
|
||||
button.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
|
||||
key = makeybutton.NewButton(button)
|
||||
|
||||
for {
|
||||
switch key.Get() {
|
||||
case makeybutton.Pressed:
|
||||
led.High()
|
||||
case makeybutton.Released:
|
||||
led.Low()
|
||||
}
|
||||
time.Sleep(30 * time.Millisecond)
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user