gobot.io/x/gobot/v2@v2.1.0/examples/microbit_blink.go (about) 1 //go:build example 2 // +build example 3 4 // 5 // Do not build by default. 6 7 /* 8 How to setup 9 You must be using a BBC Microbit microcontroller that has 10 been flashed with the firmware from @sandeepmistry 11 12 More info: 13 https://gobot.io/documentation/platforms/microbit/#how-to-install 14 15 This example requires that you wire an external LED to 16 pin number 0 on the Microbit, as this example is intended 17 to demonstrate the Microbit IOPinDriver. 18 19 You then run the Go program on your computer and communicate 20 wirelessly with the Microbit. 21 22 How to run 23 Pass the Bluetooth name or address as first param: 24 25 go run examples/microbit_blink.go "BBC micro:bit [yowza]" 26 27 NOTE: sudo is required to use BLE in Linux 28 */ 29 30 package main 31 32 import ( 33 "os" 34 "time" 35 36 "gobot.io/x/gobot/v2" 37 "gobot.io/x/gobot/v2/drivers/gpio" 38 "gobot.io/x/gobot/v2/platforms/ble" 39 "gobot.io/x/gobot/v2/platforms/microbit" 40 ) 41 42 func main() { 43 bleAdaptor := ble.NewClientAdaptor(os.Args[1]) 44 45 ubit := microbit.NewIOPinDriver(bleAdaptor) 46 led := gpio.NewLedDriver(ubit, "0") 47 48 work := func() { 49 gobot.Every(1*time.Second, func() { 50 led.Toggle() 51 }) 52 } 53 54 robot := gobot.NewRobot("bot", 55 []gobot.Connection{bleAdaptor}, 56 []gobot.Device{ubit, led}, 57 work, 58 ) 59 60 robot.Start() 61 }