gobot.io/x/gobot/v2@v2.1.0/examples/microbit_led.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 uses the Microbit's built-in LED matrix. 16 You run the Go program on your computer and communicate 17 wirelessly with the Microbit. 18 19 How to run 20 Pass the Bluetooth name or address as first param: 21 22 go run examples/microbit_led.go "BBC micro:bit [yowza]" 23 24 NOTE: sudo is required to use BLE in Linux 25 */ 26 27 package main 28 29 import ( 30 "os" 31 "time" 32 33 "gobot.io/x/gobot/v2" 34 "gobot.io/x/gobot/v2/platforms/ble" 35 "gobot.io/x/gobot/v2/platforms/microbit" 36 ) 37 38 func main() { 39 bleAdaptor := ble.NewClientAdaptor(os.Args[1]) 40 ubit := microbit.NewLEDDriver(bleAdaptor) 41 42 work := func() { 43 ubit.Blank() 44 gobot.After(1*time.Second, func() { 45 ubit.WriteText("Hello") 46 }) 47 gobot.After(7*time.Second, func() { 48 ubit.Smile() 49 }) 50 } 51 52 robot := gobot.NewRobot("blinkBot", 53 []gobot.Connection{bleAdaptor}, 54 []gobot.Device{ubit}, 55 work, 56 ) 57 58 robot.Start() 59 }