github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/src/examples/button/button.go (about) 1 package main 2 3 import ( 4 "machine" 5 "time" 6 ) 7 8 const ( 9 led = machine.LED 10 button = machine.BUTTON 11 ) 12 13 func main() { 14 led.Configure(machine.PinConfig{Mode: machine.PinOutput}) 15 button.Configure(machine.PinConfig{Mode: machine.PinInputPullup}) 16 17 for { 18 if button.Get() { 19 led.Low() 20 } else { 21 led.High() 22 } 23 24 time.Sleep(time.Millisecond * 10) 25 } 26 }