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

     1  // +build example
     2  //
     3  // Do not build by default.
     4  
     5  package main
     6  
     7  import (
     8  	"fmt"
     9  	"time"
    10  
    11  	"gobot.io/x/gobot"
    12  	"gobot.io/x/gobot/drivers/gpio"
    13  	"gobot.io/x/gobot/platforms/digispark"
    14  )
    15  
    16  func main() {
    17  	digisparkAdaptor := digispark.NewAdaptor()
    18  	led := gpio.NewLedDriver(digisparkAdaptor, "0")
    19  
    20  	work := func() {
    21  		gobot.Every(1*time.Second, func() {
    22  			led.Toggle()
    23  		})
    24  	}
    25  
    26  	robot := gobot.NewRobot("blinkBot",
    27  		[]gobot.Connection{digisparkAdaptor},
    28  		[]gobot.Device{led},
    29  		work,
    30  	)
    31  
    32  	err := robot.Start()
    33  	if err != nil {
    34  		fmt.Println(err)
    35  	}
    36  }