tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/makeybutton/main.go (about) 1 package main 2 3 import ( 4 "machine" 5 "time" 6 7 "tinygo.org/x/drivers/makeybutton" 8 ) 9 10 var ( 11 led machine.Pin = machine.LED 12 button machine.Pin = machine.D10 13 key *makeybutton.Button 14 ) 15 16 func main() { 17 led.Configure(machine.PinConfig{Mode: machine.PinOutput}) 18 key = makeybutton.NewButton(button) 19 key.Configure() 20 21 for { 22 switch key.Get() { 23 case makeybutton.Pressed: 24 led.High() 25 case makeybutton.Released: 26 led.Low() 27 } 28 // the more frequent the more responsive 29 time.Sleep(50 * time.Millisecond) 30 } 31 }