github.com/aykevl/tinygo@v0.5.0/src/examples/button2/button2.go (about) 1 package main 2 3 import ( 4 "machine" 5 "time" 6 ) 7 8 // This example assumes that you are using the pca10040 board 9 10 func main() { 11 led1 := machine.GPIO{machine.LED1} 12 led1.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT}) 13 14 led2 := machine.GPIO{machine.LED2} 15 led2.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT}) 16 17 led3 := machine.GPIO{machine.LED3} 18 led3.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT}) 19 20 led4 := machine.GPIO{machine.LED4} 21 led4.Configure(machine.GPIOConfig{Mode: machine.GPIO_OUTPUT}) 22 23 button1 := machine.GPIO{machine.BUTTON1} 24 button1.Configure(machine.GPIOConfig{Mode: machine.GPIO_INPUT_PULLUP}) 25 26 button2 := machine.GPIO{machine.BUTTON2} 27 button2.Configure(machine.GPIOConfig{Mode: machine.GPIO_INPUT_PULLUP}) 28 29 button3 := machine.GPIO{machine.BUTTON3} 30 button3.Configure(machine.GPIOConfig{Mode: machine.GPIO_INPUT_PULLUP}) 31 32 button4 := machine.GPIO{machine.BUTTON4} 33 button4.Configure(machine.GPIOConfig{Mode: machine.GPIO_INPUT_PULLUP}) 34 35 for { 36 led1.Set(button1.Get()) 37 led2.Set(button2.Get()) 38 led3.Set(button3.Get()) 39 led4.Set(button4.Get()) 40 41 time.Sleep(time.Millisecond * 10) 42 } 43 }