2023-05-20 14:25:21 +02:00
|
|
|
//go:build example
|
2017-03-13 11:01:39 -04:00
|
|
|
// +build example
|
2023-05-20 14:25:21 +02:00
|
|
|
|
2017-03-13 11:01:39 -04:00
|
|
|
//
|
|
|
|
// Do not build by default.
|
|
|
|
|
2017-01-02 22:36:30 +01:00
|
|
|
/*
|
2017-06-10 13:18:29 +02:00
|
|
|
How to setup
|
|
|
|
You must be using a WiFi-connected microcontroller,
|
|
|
|
that has been flashed with the WifiFirmata sketch.
|
|
|
|
You then run the go program on your computer, and communicate
|
|
|
|
wirelessly with the microcontroller.
|
|
|
|
|
|
|
|
How to run
|
|
|
|
Pass the IP address/port as first param:
|
2017-01-02 22:36:30 +01:00
|
|
|
|
2017-01-02 22:37:07 +01:00
|
|
|
go run examples/wifi_firmata_blink.go 192.168.0.39:3030
|
2017-01-02 22:36:30 +01:00
|
|
|
*/
|
|
|
|
|
2017-01-02 21:40:20 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
2024-02-11 15:34:50 +01:00
|
|
|
"fmt"
|
2017-01-02 21:40:20 +01:00
|
|
|
"os"
|
|
|
|
"time"
|
|
|
|
|
2023-05-20 14:25:21 +02:00
|
|
|
"gobot.io/x/gobot/v2"
|
|
|
|
"gobot.io/x/gobot/v2/drivers/gpio"
|
|
|
|
"gobot.io/x/gobot/v2/platforms/firmata"
|
2017-01-02 21:40:20 +01:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
firmataAdaptor := firmata.NewTCPAdaptor(os.Args[1])
|
2017-01-02 22:02:43 +01:00
|
|
|
led := gpio.NewLedDriver(firmataAdaptor, "2")
|
2017-01-02 21:40:20 +01:00
|
|
|
|
|
|
|
work := func() {
|
|
|
|
gobot.Every(1*time.Second, func() {
|
2024-02-11 15:34:50 +01:00
|
|
|
if err := led.Toggle(); err != nil {
|
|
|
|
fmt.Println(err)
|
|
|
|
}
|
2017-01-02 21:40:20 +01:00
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
robot := gobot.NewRobot("bot",
|
|
|
|
[]gobot.Connection{firmataAdaptor},
|
|
|
|
[]gobot.Device{led},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
2024-02-11 15:34:50 +01:00
|
|
|
if err := robot.Start(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2017-01-02 21:40:20 +01:00
|
|
|
}
|