2014-04-26 03:11:51 -07:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
2014-07-09 16:51:00 -07:00
|
|
|
|
2014-04-26 03:11:51 -07:00
|
|
|
"github.com/hybridgroup/gobot"
|
2014-05-22 19:22:14 -07:00
|
|
|
"github.com/hybridgroup/gobot/platforms/firmata"
|
|
|
|
"github.com/hybridgroup/gobot/platforms/gpio"
|
2014-04-26 03:11:51 -07:00
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
2014-05-22 19:22:14 -07:00
|
|
|
gbot := gobot.NewGobot()
|
2014-07-08 18:36:14 -07:00
|
|
|
|
2014-05-22 19:22:14 -07:00
|
|
|
firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0")
|
2014-06-06 18:58:04 -07:00
|
|
|
sensor := gpio.NewAnalogSensorDriver(firmataAdaptor, "sensor", "0")
|
2014-07-09 16:51:00 -07:00
|
|
|
led := gpio.NewLedDriver(firmataAdaptor, "led", "3")
|
2014-04-26 03:11:51 -07:00
|
|
|
|
|
|
|
work := func() {
|
2016-09-01 12:17:43 +02:00
|
|
|
sensor.On(gpio.Data, func(data interface{}) {
|
2014-07-10 17:21:21 -07:00
|
|
|
brightness := uint8(
|
|
|
|
gobot.ToScale(gobot.FromScale(float64(data.(int)), 0, 1024), 0, 255),
|
|
|
|
)
|
2014-06-28 17:18:16 -07:00
|
|
|
fmt.Println("sensor", data)
|
2014-04-26 03:11:51 -07:00
|
|
|
fmt.Println("brightness", brightness)
|
|
|
|
led.Brightness(brightness)
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
2014-07-08 18:36:14 -07:00
|
|
|
robot := gobot.NewRobot("sensorBot",
|
|
|
|
[]gobot.Connection{firmataAdaptor},
|
|
|
|
[]gobot.Device{sensor, led},
|
|
|
|
work,
|
|
|
|
)
|
|
|
|
|
|
|
|
gbot.AddRobot(robot)
|
2014-04-26 03:11:51 -07:00
|
|
|
|
2014-05-22 19:22:14 -07:00
|
|
|
gbot.Start()
|
2014-04-26 03:11:51 -07:00
|
|
|
}
|