Index

Metal Gobot

Use Metal Gobot when you want to use the individual Gobot packages yourself to have the greatest control, or to more easily integrate Gobot functionality into your existing Golang programs.

Let's revisit the "Blink" code example from the "Getting Started" page, written using "Metal Gobot" style:

package main

import (
        "gobot.io/x/gobot/drivers/gpio"
        "gobot.io/x/gobot/platforms/intel-iot/edison"
        "time"
)

func main() {
        e := edison.NewAdaptor()
        e.Connect()

        led := gpio.NewLedDriver(e, "13")
        led.Start()

        for {
                led.Toggle()
                time.Sleep(1000 * time.Millisecond)
        }
}

This is a nice simple example. You Connect() the Adaptor, you Start() the Driver, and away you go.

Here is a slightly more sophsticated example that uses Metal Gobot along with an Event channel:

Metal Button

package main

import (
        "fmt"

        "gobot.io/x/gobot/drivers/gpio"
        "gobot.io/x/gobot/platforms/intel-iot/edison"
)

func main() {
        e := edison.NewAdaptor()
        e.Connect()

        led := gpio.NewLedDriver(e, "13")
        led.Start()
        led.Off()

        button := gpio.NewButtonDriver(e, "5")
        button.Start()

        buttonEvents := button.Subscribe()
        for {
                select {
                case event := <-buttonEvents:
                        fmt.Println("Event:", event.Name, event.Data)
                        if event.Name == gpio.ButtonPush {
                                led.Toggle()
                        }
                }
        }
}

How to use Metal Gobot

When using Metal Gobot you need to make calls directly to Adaptors and/or Drivers yourself.

You will need to call Connect() on each Adaptor yourself. Likewise, you will need to call Start() on each Driver.

Once this is done, you can then use the Adaptors and Drivers directly however you wish.