github.com/aykevl/tinygo@v0.5.0/src/examples/button/button.go (about) 1 package main 2 3 import ( 4 "machine" 5 "time" 6 ) 7 8 // This example assumes that the button is connected to pin 8. Change the value 9 // below to use a different pin. 10 const buttonPin = 8 11 12 func main() { 13 led := machine.GPIO{machine.LED} 14 led.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT}) 15 16 button := machine.GPIO{buttonPin} 17 button.Configure(machine.GPIOConfig{Mode: machine.GPIO_INPUT}) 18 19 for { 20 if button.Get() { 21 led.Low() 22 } else { 23 led.High() 24 } 25 26 time.Sleep(time.Millisecond * 10) 27 } 28 }