github.com/tinygo-org/tinygo@v0.31.3-0.20240404173401-90b0bf646c27/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.LED1
    12  	led1.Configure(machine.PinConfig{Mode: machine.PinOutput})
    13  
    14  	led2 := machine.LED2
    15  	led2.Configure(machine.PinConfig{Mode: machine.PinOutput})
    16  
    17  	led3 := machine.LED3
    18  	led3.Configure(machine.PinConfig{Mode: machine.PinOutput})
    19  
    20  	led4 := machine.LED4
    21  	led4.Configure(machine.PinConfig{Mode: machine.PinOutput})
    22  
    23  	button1 := machine.BUTTON1
    24  	button1.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
    25  
    26  	button2 := machine.BUTTON2
    27  	button2.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
    28  
    29  	button3 := machine.BUTTON3
    30  	button3.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
    31  
    32  	button4 := machine.BUTTON4
    33  	button4.Configure(machine.PinConfig{Mode: machine.PinInputPullup})
    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  }