gobot.io/x/gobot@v1.16.0/examples/microbit_blink.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 requires that you wire an external LED to
    14   pin number 0 on the Microbit, as this example is intended
    15   to demonstrate the Microbit IOPinDriver.
    16  
    17   You then run the Go program on your computer and communicate
    18   wirelessly with the Microbit.
    19  
    20   How to run
    21   Pass the Bluetooth name or address as first param:
    22  
    23  	go run examples/microbit_blink.go "BBC micro:bit [yowza]"
    24  
    25   NOTE: sudo is required to use BLE in Linux
    26  */
    27  
    28  package main
    29  
    30  import (
    31  	"os"
    32  	"time"
    33  
    34  	"gobot.io/x/gobot"
    35  	"gobot.io/x/gobot/drivers/gpio"
    36  	"gobot.io/x/gobot/platforms/ble"
    37  	"gobot.io/x/gobot/platforms/microbit"
    38  )
    39  
    40  func main() {
    41  	bleAdaptor := ble.NewClientAdaptor(os.Args[1])
    42  
    43  	ubit := microbit.NewIOPinDriver(bleAdaptor)
    44  	led := gpio.NewLedDriver(ubit, "0")
    45  
    46  	work := func() {
    47  		gobot.Every(1*time.Second, func() {
    48  			led.Toggle()
    49  		})
    50  	}
    51  
    52  	robot := gobot.NewRobot("bot",
    53  		[]gobot.Connection{bleAdaptor},
    54  		[]gobot.Device{ubit, led},
    55  		work,
    56  	)
    57  
    58  	robot.Start()
    59  }