func main() { master := gobot.NewMaster() firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0") red := gpio.NewLedDriver(firmataAdaptor, "7") red.SetName("red") green := gpio.NewLedDriver(firmataAdaptor, "6") green.SetName("green") blue := gpio.NewLedDriver(firmataAdaptor, "5") blue.SetName("blue") work := func() { checkTravis(master.Robot("travis")) gobot.Every(10*time.Second, func() { checkTravis(master.Robot("travis")) }) } robot := gobot.NewRobot("travis", []gobot.Connection{firmataAdaptor}, []gobot.Device{red, green, blue}, work, ) master.AddRobot(robot) master.Start() }
func main() { e := joule.NewAdaptor() led0 := gpio.NewLedDriver(e, "100") led1 := gpio.NewLedDriver(e, "101") led2 := gpio.NewLedDriver(e, "102") led3 := gpio.NewLedDriver(e, "103") work := func() { led0.Off() led1.Off() led2.Off() led3.Off() gobot.Every(1*time.Second, func() { led0.Toggle() }) gobot.Every(2*time.Second, func() { led1.Toggle() }) gobot.Every(4*time.Second, func() { led2.Toggle() }) gobot.Every(8*time.Second, func() { led3.Toggle() }) } robot := gobot.NewRobot("blinkBot", []gobot.Connection{e}, []gobot.Device{led0, led1, led2, led3}, work, ) robot.Start() }
func main() { firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0") led1 := gpio.NewLedDriver(firmataAdaptor, "3") led2 := gpio.NewLedDriver(firmataAdaptor, "4") button := gpio.NewButtonDriver(firmataAdaptor, "2") sensor := gpio.NewAnalogSensorDriver(firmataAdaptor, "0") work := func() { gobot.Every(1*time.Second, func() { led1.Toggle() }) gobot.Every(2*time.Second, func() { led2.Toggle() }) button.On(gpio.ButtonPush, func(data interface{}) { led2.On() }) button.On(gpio.ButtonRelease, func(data interface{}) { led2.Off() }) sensor.On(gpio.Data, func(data interface{}) { fmt.Println("sensor", data) }) } robot := gobot.NewRobot("bot", []gobot.Connection{firmataAdaptor}, []gobot.Device{led1, led2, button, sensor}, work, ) robot.Start() }
func main() { core := particle.NewAdaptor(os.Args[1], os.Args[2]) led := gpio.NewLedDriver(core, "A1") work := func() { brightness := uint8(0) fadeAmount := uint8(25) gobot.Every(500*time.Millisecond, func() { led.Brightness(brightness) brightness = brightness + fadeAmount if brightness == 0 || brightness == 255 { fadeAmount = -fadeAmount } }) } robot := gobot.NewRobot("spark", []gobot.Connection{core}, []gobot.Device{led}, work, ) robot.Start() }
func main() { r := raspi.NewAdaptor() button := gpio.NewButtonDriver(r, "11") led := gpio.NewLedDriver(r, "7") work := func() { button.On(gpio.ButtonPush, func(data interface{}) { fmt.Println("button pressed") led.On() }) button.On(gpio.ButtonRelease, func(data interface{}) { fmt.Println("button released") led.Off() }) } robot := gobot.NewRobot("buttonBot", []gobot.Connection{r}, []gobot.Device{button, led}, work, ) robot.Start() }
func main() { master := gobot.NewMaster() api.NewAPI(master).Start() e := edison.NewAdaptor() button := gpio.NewButtonDriver(e, "2") led := gpio.NewLedDriver(e, "4") work := func() { button.On(gpio.ButtonPush, func(data interface{}) { led.On() }) button.On(gpio.ButtonRelease, func(data interface{}) { led.Off() }) } robot := gobot.NewRobot("buttonBot", []gobot.Connection{e}, []gobot.Device{led, button}, work, ) master.AddRobot(robot) master.Start() }
func main() { digisparkAdaptor := digispark.NewAdaptor() led := gpio.NewLedDriver(digisparkAdaptor, "0") work := func() { brightness := uint8(0) fadeAmount := uint8(15) gobot.Every(100*time.Millisecond, func() { led.Brightness(brightness) brightness = brightness + fadeAmount if brightness == 0 || brightness == 255 { fadeAmount = -fadeAmount } }) } robot := gobot.NewRobot("pwmBot", []gobot.Connection{digisparkAdaptor}, []gobot.Device{led}, work, ) robot.Start() }
func main() { mqttAdaptor := mqtt.NewAdaptor("tcp://test.mosquitto.org:1883", "blinker") firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0") led := gpio.NewLedDriver(firmataAdaptor, "13") work := func() { mqttAdaptor.On("lights/on", func(data []byte) { led.On() }) mqttAdaptor.On("lights/off", func(data []byte) { led.Off() }) data := []byte("") gobot.Every(1*time.Second, func() { mqttAdaptor.Publish("lights/on", data) }) gobot.Every(2*time.Second, func() { mqttAdaptor.Publish("lights/off", data) }) } robot := gobot.NewRobot("mqttBot", []gobot.Connection{mqttAdaptor, firmataAdaptor}, []gobot.Device{led}, work, ) robot.Start() }
func main() { firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0") sensor := gpio.NewPIRMotionDriver(firmataAdaptor, "5") led := gpio.NewLedDriver(firmataAdaptor, "13") work := func() { sensor.On(gpio.MotionDetected, func(data interface{}) { fmt.Println(gpio.MotionDetected) led.On() }) sensor.On(gpio.MotionStopped, func(data interface{}) { fmt.Println(gpio.MotionStopped) led.Off() }) } robot := gobot.NewRobot("motionBot", []gobot.Connection{firmataAdaptor}, []gobot.Device{sensor, led}, work, ) robot.Start() }
// Example of a simple led toggle without the initialization of // the entire gobot framework. // This might be useful if you want to use gobot as another // golang library to interact with sensors and other devices. func main() { f := firmata.NewAdaptor("/dev/ttyACM0") f.Connect() led := gpio.NewLedDriver(f, "13") led.Start() for { led.Toggle() time.Sleep(1000 * time.Millisecond) } }
// Example of a simple led toggle without the initialization of // the entire gobot framework. // This might be useful if you want to use gobot as another // golang library to interact with sensors and other devices. func main() { e := edison.NewAdaptor() e.Connect() led := gpio.NewLedDriver(e, "13") led.Start() for { led.Toggle() time.Sleep(1000 * time.Millisecond) } }
func main() { master := gobot.NewMaster() api.NewAPI(master).Start() digisparkAdaptor := digispark.NewAdaptor() led := gpio.NewLedDriver(digisparkAdaptor, "0") robot := gobot.NewRobot("digispark", []gobot.Connection{digisparkAdaptor}, []gobot.Device{led}, ) master.AddRobot(robot) master.Start() }
func main() { firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0") led := gpio.NewLedDriver(firmataAdaptor, "13") work := func() { gobot.Every(1*time.Second, func() { led.Toggle() }) } robot := gobot.NewRobot("bot", []gobot.Connection{firmataAdaptor}, []gobot.Device{led}, work, ) robot.Start() }
func main() { chipAdaptor := chip.NewAdaptor() led := gpio.NewLedDriver(chipAdaptor, "XIO-P6") work := func() { gobot.Every(1*time.Second, func() { led.Toggle() }) } robot := gobot.NewRobot("blinkBot", []gobot.Connection{chipAdaptor}, []gobot.Device{led}, work, ) robot.Start() }
func main() { digisparkAdaptor := digispark.NewAdaptor() led := gpio.NewLedDriver(digisparkAdaptor, "0") work := func() { gobot.Every(1*time.Second, func() { led.Toggle() }) } robot := gobot.NewRobot("blinkBot", []gobot.Connection{digisparkAdaptor}, []gobot.Device{led}, work, ) robot.Start() }
func main() { e := joule.NewAdaptor() led := gpio.NewLedDriver(e, "100") work := func() { gobot.Every(1*time.Second, func() { led.Toggle() }) } robot := gobot.NewRobot("blinkBot", []gobot.Connection{e}, []gobot.Device{led}, work, ) robot.Start() }
func main() { r := raspi.NewAdaptor() led := gpio.NewLedDriver(r, "7") work := func() { gobot.Every(1*time.Second, func() { led.Toggle() }) } robot := gobot.NewRobot("blinkBot", []gobot.Connection{r}, []gobot.Device{led}, work, ) robot.Start() }
func main() { firmataAdaptor := firmata.NewTCPAdaptor(os.Args[1]) led := gpio.NewLedDriver(firmataAdaptor, "2") work := func() { gobot.Every(1*time.Second, func() { led.Toggle() }) } robot := gobot.NewRobot("bot", []gobot.Connection{firmataAdaptor}, []gobot.Device{led}, work, ) robot.Start() }
func main() { core := particle.NewAdaptor(os.Args[1], os.Args[2]) led := gpio.NewLedDriver(core, "D7") work := func() { gobot.Every(1*time.Second, func() { led.Toggle() }) } robot := gobot.NewRobot("spark", []gobot.Connection{core}, []gobot.Device{led}, work, ) robot.Start() }
func main() { beagleboneAdaptor := beaglebone.NewAdaptor() led := gpio.NewLedDriver(beagleboneAdaptor, "P9_12") work := func() { gobot.Every(1*time.Second, func() { led.Toggle() }) } robot := gobot.NewRobot("blinkBot", []gobot.Connection{beagleboneAdaptor}, []gobot.Device{led}, work, ) robot.Start() }
func main() { f := firmata.NewAdaptor("/dev/ttyACM0") f.Connect() led := gpio.NewLedDriver(f, "13") led.Start() led.Off() button := gpio.NewButtonDriver(f, "5") button.Start() buttonEvents := button.Subscribe() for { select { case event := <-buttonEvents: fmt.Println("Event:", event.Name, event.Data) if event.Name == gpio.ButtonPush { led.Toggle() } } } }
func main() { e := edison.NewAdaptor() e.Connect() led := gpio.NewLedDriver(e, "13") led.Start() led.Off() button := gpio.NewButtonDriver(e, "5") button.Start() buttonEvents := button.Subscribe() for { select { case event := <-buttonEvents: fmt.Println("Event:", event.Name, event.Data) if event.Name == gpio.ButtonPush { led.Toggle() } } } }
func main() { e := edison.NewAdaptor() led := gpio.NewLedDriver(e, "13") // Uncomment the line below if you are using a Sparkfun // Edison board with the GPIO block // e.SetBoard("sparkfun") work := func() { gobot.Every(1*time.Second, func() { led.Toggle() }) } robot := gobot.NewRobot("blinkBot", []gobot.Connection{e}, []gobot.Device{led}, work, ) robot.Start() }
func main() { chipAdaptor := chip.NewAdaptor() button := gpio.NewButtonDriver(chipAdaptor, "XIO-P6") led := gpio.NewLedDriver(chipAdaptor, "XIO-P7") work := func() { button.On(gpio.ButtonPush, func(data interface{}) { led.On() }) button.On(gpio.ButtonRelease, func(data interface{}) { led.Off() }) } robot := gobot.NewRobot("buttonBot", []gobot.Connection{chipAdaptor}, []gobot.Device{button, led}, work, ) robot.Start() }
func main() { e := edison.NewAdaptor() button := gpio.NewButtonDriver(e, "5") led := gpio.NewLedDriver(e, "13") work := func() { button.On(gpio.ButtonPush, func(data interface{}) { led.On() }) button.On(gpio.ButtonRelease, func(data interface{}) { led.Off() }) } robot := gobot.NewRobot("buttonBot", []gobot.Connection{e}, []gobot.Device{led, button}, work, ) robot.Start() }
func main() { firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0") button := gpio.NewButtonDriver(firmataAdaptor, "5") led := gpio.NewLedDriver(firmataAdaptor, "13") work := func() { button.On(gpio.ButtonPush, func(data interface{}) { led.On() }) button.On(gpio.ButtonRelease, func(data interface{}) { led.Off() }) } robot := gobot.NewRobot("buttonBot", []gobot.Connection{firmataAdaptor}, []gobot.Device{button, led}, work, ) robot.Start() }
func main() { core := particle.NewAdaptor(os.Args[1], os.Args[2]) led := gpio.NewLedDriver(core, "D7") button := gpio.NewButtonDriver(core, "D5") work := func() { button.On(button.Event("push"), func(data interface{}) { led.On() }) button.On(button.Event("release"), func(data interface{}) { led.Off() }) } robot := gobot.NewRobot("spark", []gobot.Connection{core}, []gobot.Device{button, led}, work, ) robot.Start() }
func main() { beagleboneAdaptor := beaglebone.NewAdaptor() sensor := gpio.NewAnalogSensorDriver(beagleboneAdaptor, "P9_33") led := gpio.NewLedDriver(beagleboneAdaptor, "P9_14") work := func() { sensor.On(sensor.Event("data"), func(data interface{}) { brightness := uint8( gobot.ToScale(gobot.FromScale(float64(data.(int)), 0, 1024), 0, 255), ) fmt.Println("sensor", data) fmt.Println("brightness", brightness) led.Brightness(brightness) }) } robot := gobot.NewRobot("sensorBot", []gobot.Connection{beagleboneAdaptor}, []gobot.Device{sensor, led}, work, ) robot.Start() }
func main() { e := edison.NewAdaptor() sensor := aio.NewAnalogSensorDriver(e, "0") led := gpio.NewLedDriver(e, "3") work := func() { sensor.On(aio.Data, func(data interface{}) { brightness := uint8( gobot.ToScale(gobot.FromScale(float64(data.(int)), 0, 4096), 0, 255), ) fmt.Println("sensor", data) fmt.Println("brightness", brightness) led.Brightness(brightness) }) } robot := gobot.NewRobot("sensorBot", []gobot.Connection{e}, []gobot.Device{sensor, led}, work, ) master.Start() }
func main() { master := gobot.NewMaster() a := api.NewAPI(master) a.Start() firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0") led := gpio.NewLedDriver(firmataAdaptor, "13") work := func() { gobot.Every(1*time.Second, func() { led.Toggle() }) } robot := gobot.NewRobot("bot", []gobot.Connection{firmataAdaptor}, []gobot.Device{led}, work, ) master.AddRobot(robot) master.Start() }