tinygo.org/x/drivers@v0.27.1-0.20240509133757-7dbca2a54349/examples/shifter/main.go (about) 1 // This example is designed to implement the button shifter for a PyBadge. 2 package main 3 4 import ( 5 "time" 6 7 "tinygo.org/x/drivers/shifter" 8 ) 9 10 func main() { 11 buttons := shifter.NewButtons() 12 buttons.Configure() 13 14 for { 15 // Update the pins state, to later be returned by .Get() 16 buttons.ReadInput() 17 18 if buttons.Pins[shifter.BUTTON_LEFT].Get() { 19 println("Button LEFT pressed") 20 } 21 if buttons.Pins[shifter.BUTTON_UP].Get() { 22 println("Button UP pressed") 23 } 24 if buttons.Pins[shifter.BUTTON_DOWN].Get() { 25 println("Button DOWN pressed") 26 } 27 if buttons.Pins[shifter.BUTTON_RIGHT].Get() { 28 println("Button RIGHT pressed") 29 } 30 if buttons.Pins[shifter.BUTTON_SELECT].Get() { 31 println("Button SELECT pressed") 32 } 33 if buttons.Pins[shifter.BUTTON_START].Get() { 34 println("Button START pressed") 35 } 36 if buttons.Pins[shifter.BUTTON_A].Get() { 37 println("Button A pressed") 38 } 39 if buttons.Pins[shifter.BUTTON_B].Get() { 40 println("Button B pressed") 41 } 42 time.Sleep(100 * time.Millisecond) 43 } 44 }