gobot.io/x/gobot@v1.16.0/examples/firmata_blink.go (about)

     1  // +build example
     2  //
     3  // Do not build by default.
     4  
     5  /*
     6   How to run
     7   Pass serial port to use as the first param:
     8  
     9  	go run examples/firmata_blink.go /dev/ttyACM0
    10  */
    11  
    12  package main
    13  
    14  import (
    15  	"fmt"
    16  	"os"
    17  	"time"
    18  
    19  	"gobot.io/x/gobot"
    20  	"gobot.io/x/gobot/drivers/gpio"
    21  	"gobot.io/x/gobot/platforms/firmata"
    22  )
    23  
    24  func main() {
    25  	firmataAdaptor := firmata.NewAdaptor(os.Args[1])
    26  	led := gpio.NewLedDriver(firmataAdaptor, "13")
    27  
    28  	work := func() {
    29  		gobot.Every(1*time.Second, func() {
    30  			led.Toggle()
    31  		})
    32  	}
    33  
    34  	robot := gobot.NewRobot("bot",
    35  		[]gobot.Connection{firmataAdaptor},
    36  		[]gobot.Device{led},
    37  		work,
    38  	)
    39  
    40  	err := robot.Start()
    41  	if err != nil {
    42  		fmt.Println(err)
    43  	}
    44  }