Go: Rasbperry Pi で LED を使う

##プログラム##
>GPIO16 のピン番号は 36 です。

```go:led.go
package main

import (
        "time"
        "fmt"
        "os"

        "gobot.io/x/gobot"
        "gobot.io/x/gobot/drivers/gpio"
        "gobot.io/x/gobot/platforms/raspi"
)

func main() {
	fmt.Fprintf (os.Stderr,"*** 開始 ***\n")
        r := raspi.NewAdaptor()
        led := gpio.NewLedDriver(r, "36")
	fmt.Fprintf (os.Stderr,"*** bbb ***\n")

        work := func() {
                gobot.Every(2*time.Second, func() {
			fmt.Fprintf (os.Stderr,"*** led.Toggle() ***\n")
                        led.Toggle()
                })
        }

        robot := gobot.NewRobot("blinkLED",
                []gobot.Connection{r},
                []gobot.Device{led},
                work,
        )

        robot.Start()
 }
```

##最初のトライ##

```text
$ go run led.go 
led.go:8:9: no required module provides package gobot.io/x/gobot: go.mod file not found in current directory or any parent directory; see 'go help modules'
led.go:9:9: no required module provides package gobot.io/x/gobot/drivers/gpio: go.mod file not found in current directory or any parent directory; see 'go help modules'
led.go:10:9: no required module provides package gobot.io/x/gobot/platforms/raspi: go.mod file not found in current directory or any parent directory; see 'go help modules'
```

対策

```text
$ go mod init led
go: creating new go.mod: module led
go: to add module requirements and sums:
	go mod tidy
```

##2度目のトライ##

```text
$ go run led.go 
led.go:8:9: no required module provides package gobot.io/x/gobot; to add it:
	go get gobot.io/x/gobot
led.go:9:9: no required module provides package gobot.io/x/gobot/drivers/gpio; to add it:
	go get gobot.io/x/gobot/drivers/gpio
led.go:10:9: no required module provides package gobot.io/x/gobot/platforms/raspi; to add it:
	go get gobot.io/x/gobot/platforms/raspi
```

対策

```text
$ go get gobot.io/x/gobot
go get: added github.com/gobuffalo/uuid v2.0.5+incompatible
go get: added github.com/gofrs/uuid v3.2.0+incompatible
go get: added github.com/hashicorp/errwrap v1.0.0
go get: added github.com/hashicorp/go-multierror v1.0.0
go get: added gobot.io/x/gobot v1.15.0
```

##3度目のトライ##

```text
$ go run led.go 
../../go/pkg/mod/gobot.io/x/gobot@v1.15.0/drivers/i2c/adxl345_driver.go:6:2: missing go.sum entry for module providing package github.com/pkg/errors (imported by gobot.io/x/gobot/drivers/i2c); to add:
	go get gobot.io/x/gobot/drivers/i2c@v1.15.0
../../go/pkg/mod/gobot.io/x/gobot@v1.15.0/drivers/i2c/sht2x_driver.go:27:2: missing go.sum entry for module providing package github.com/sigurn/crc8 (imported by gobot.io/x/gobot/drivers/i2c); to add:
	go get gobot.io/x/gobot/drivers/i2c@v1.15.0
../../go/pkg/mod/gobot.io/x/gobot@v1.15.0/drivers/spi/spi.go:4:2: missing go.sum entry for module providing package periph.io/x/periph/conn/physic (imported by gobot.io/x/gobot/drivers/spi); to add:
	go get gobot.io/x/gobot/drivers/spi@v1.15.0
../../go/pkg/mod/gobot.io/x/gobot@v1.15.0/drivers/spi/spi.go:5:2: missing go.sum entry for module providing package periph.io/x/periph/conn/spi (imported by gobot.io/x/gobot/drivers/spi); to add:
	go get gobot.io/x/gobot/drivers/spi@v1.15.0
../../go/pkg/mod/gobot.io/x/gobot@v1.15.0/drivers/spi/spi.go:6:2: missing go.sum entry for module providing package periph.io/x/periph/host/sysfs (imported by gobot.io/x/gobot/drivers/spi); to add:
	go get gobot.io/x/gobot/drivers/spi@v1.15.0
```

対策

```text
$ go get gobot.io/x/gobot/drivers/i2c@v1.15.0
```

##4度目のトライ##

```text
$ go run led.go 
../../go/pkg/mod/gobot.io/x/gobot@v1.15.0/drivers/spi/spi.go:4:2: missing go.sum entry for module providing package periph.io/x/periph/conn/physic (imported by gobot.io/x/gobot/drivers/spi); to add:
	go get gobot.io/x/gobot/drivers/spi@v1.15.0
../../go/pkg/mod/gobot.io/x/gobot@v1.15.0/drivers/spi/spi.go:5:2: missing go.sum entry for module providing package periph.io/x/periph/conn/spi (imported by gobot.io/x/gobot/drivers/spi); to add:
	go get gobot.io/x/gobot/drivers/spi@v1.15.0
../../go/pkg/mod/gobot.io/x/gobot@v1.15.0/drivers/spi/spi.go:6:2: missing go.sum entry for module providing package periph.io/x/periph/host/sysfs (imported by gobot.io/x/gobot/drivers/spi); to add:
	go get gobot.io/x/gobot/drivers/spi@v1.15.0
```

対策

```text
$ go get gobot.io/x/gobot/drivers/spi@v1.15.0
```

##5度目のトライ##
>ちゃんと、GPIO16 のLED が点滅しました。

```text
$ go run led.go 
*** 開始 ***
*** bbb ***
2021/10/06 18:00:17 Initializing connections...
2021/10/06 18:00:17 Initializing connection RaspberryPi-6069818E ...
2021/10/06 18:00:17 Initializing devices...
2021/10/06 18:00:17 Initializing device LED-20B37CA6 ...
2021/10/06 18:00:17 Robot blinkLED initialized.
2021/10/06 18:00:17 Starting Robot blinkLED ...
2021/10/06 18:00:17 Starting connections...
2021/10/06 18:00:17 Starting connection RaspberryPi-6069818E...
2021/10/06 18:00:17 Starting devices...
2021/10/06 18:00:17 Starting device LED-20B37CA6 on pin 36...
2021/10/06 18:00:17 Starting work...
*** led.Toggle() ***
*** led.Toggle() ***
*** led.Toggle() ***
*** led.Toggle() ***
*** led.Toggle() ***
```

次のバージョンで確認しました。

```text
$ go version
go version go1.17.1 linux/arm
```