2023-05-20 20:25:21 +08:00
|
|
|
//go:build example
|
2018-09-08 03:26:45 +08:00
|
|
|
// +build example
|
2023-05-20 20:25:21 +08:00
|
|
|
|
2018-09-08 03:26:45 +08:00
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-02-11 22:34:50 +08:00
|
|
|
"fmt"
|
2018-09-08 03:26:45 +08:00
|
|
|
"time"
|
|
|
|
|
2023-05-20 20:25:21 +08:00
|
|
|
"gobot.io/x/gobot/v2"
|
|
|
|
"gobot.io/x/gobot/v2/drivers/gpio"
|
|
|
|
"gobot.io/x/gobot/v2/platforms/upboard/up2"
|
2018-09-08 03:26:45 +08:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
b := up2.NewAdaptor()
|
2018-09-08 20:25:20 +08:00
|
|
|
red := gpio.NewLedDriver(b, up2.LEDRed)
|
|
|
|
blue := gpio.NewLedDriver(b, up2.LEDBlue)
|
|
|
|
green := gpio.NewLedDriver(b, up2.LEDGreen)
|
|
|
|
yellow := gpio.NewLedDriver(b, up2.LEDYellow)
|
2018-09-08 03:26:45 +08:00
|
|
|
|
|
|
|
work := func() {
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := red.Off(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
if err := blue.Off(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
if err := green.Off(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
|
|
|
if err := yellow.Off(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2018-09-08 03:26:45 +08:00
|
|
|
|
|
|
|
gobot.Every(1*time.Second, func() {
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := red.Toggle(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2018-09-08 03:26:45 +08:00
|
|
|
})
|
|
|
|
gobot.Every(2*time.Second, func() {
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := green.Toggle(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2018-09-08 03:26:45 +08:00
|
|
|
})
|
|
|
|
gobot.Every(4*time.Second, func() {
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := yellow.Toggle(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2018-09-08 03:26:45 +08:00
|
|
|
})
|
|
|
|
gobot.Every(8*time.Second, func() {
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := blue.Toggle(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2018-09-08 03:26:45 +08:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("blinkBot",
|
|
|
|
[]gobot.Connection{b},
|
|
|
|
[]gobot.Device{red, blue, green, yellow},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2024-02-11 22:34:50 +08:00
|
|
|
if err := robot.Start(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2018-09-08 03:26:45 +08:00
|
|
|
}
|