gobot.io/x/gobot@v1.16.0/examples/microbit_buttons.go (about) 1 // +build example 2 // 3 // Do not build by default. 4 5 /* 6 How to setup 7 You must be using a BBC Microbit microcontroller that has 8 been flashed with the firmware from @sandeepmistry 9 10 More info: 11 https://gobot.io/documentation/platforms/microbit/#how-to-install 12 13 This example uses the Microbit's built-in buttons. You run 14 the Go program on your computer and communicate wirelessly 15 with the Microbit. 16 17 How to run 18 Pass the Bluetooth name or address as first param: 19 20 go run examples/microbit_buttons_led.go "BBC micro:bit [yowza]" 21 */ 22 23 package main 24 25 import ( 26 "fmt" 27 "os" 28 29 "gobot.io/x/gobot" 30 "gobot.io/x/gobot/platforms/ble" 31 "gobot.io/x/gobot/platforms/microbit" 32 ) 33 34 func main() { 35 bleAdaptor := ble.NewClientAdaptor(os.Args[1]) 36 ubit := microbit.NewButtonDriver(bleAdaptor) 37 38 work := func() { 39 ubit.On(microbit.ButtonA, func(data interface{}) { 40 fmt.Println("button A", data) 41 }) 42 43 ubit.On(microbit.ButtonB, func(data interface{}) { 44 fmt.Println("button B", data) 45 }) 46 } 47 48 robot := gobot.NewRobot("buttonBot", 49 []gobot.Connection{bleAdaptor}, 50 []gobot.Device{ubit}, 51 work, 52 ) 53 54 robot.Start() 55 }