func main() { gbot := gobot.NewGobot() r := raspi.NewRaspiAdaptor("raspi") button := gpio.NewButtonDriver(r, "button", "11") led := gpio.NewLedDriver(r, "led", "7") work := func() { gobot.On(button.Event("push"), func(data interface{}) { fmt.Println("button pressed") led.On() }) gobot.On(button.Event("release"), func(data interface{}) { fmt.Println("button released") led.Off() }) } robot := gobot.NewRobot("buttonBot", []gobot.Connection{r}, []gobot.Device{button, led}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() chipAdaptor := chip.NewChipAdaptor("chip") wiichuck := i2c.NewWiichuckDriver(chipAdaptor, "wiichuck") work := func() { gobot.On(wiichuck.Event("joystick"), func(data interface{}) { fmt.Println("joystick", data) }) gobot.On(wiichuck.Event("c"), func(data interface{}) { fmt.Println("c") }) gobot.On(wiichuck.Event("z"), func(data interface{}) { fmt.Println("z") }) gobot.On(wiichuck.Event("error"), func(data interface{}) { fmt.Println("Wiichuck error:", data) }) } robot := gobot.NewRobot("chuck", []gobot.Connection{chipAdaptor}, []gobot.Device{wiichuck}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() a := api.NewAPI(gbot) a.Start() // digital board := edison.NewEdisonAdaptor("edison") button = gpio.NewGroveButtonDriver(board, "button", "2") blue = gpio.NewGroveLedDriver(board, "blue", "3") green = gpio.NewGroveLedDriver(board, "green", "4") red = gpio.NewGroveLedDriver(board, "red", "5") buzzer = gpio.NewGroveBuzzerDriver(board, "buzzer", "7") touch = gpio.NewGroveTouchDriver(board, "touch", "8") // analog rotary = gpio.NewGroveRotaryDriver(board, "rotary", "0") sensor = gpio.NewGroveTemperatureSensorDriver(board, "sensor", "1") sound = gpio.NewGroveSoundSensorDriver(board, "sound", "2") work := func() { Reset() gobot.On(button.Event(gpio.Push), func(data interface{}) { TurnOff() fmt.Println("On!") blue.On() }) gobot.On(button.Event(gpio.Release), func(data interface{}) { Reset() }) gobot.On(touch.Event(gpio.Push), func(data interface{}) { Doorbell() }) gobot.On(rotary.Event("data"), func(data interface{}) { fmt.Println("rotary", data) }) gobot.On(sound.Event("data"), func(data interface{}) { DetectSound(data.(int)) }) gobot.Every(1*time.Second, func() { CheckFireAlarm() }) } robot := gobot.NewRobot("airlock", []gobot.Connection{board}, []gobot.Device{button, blue, green, red, buzzer, touch, rotary, sensor, sound}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() e := edison.NewEdisonAdaptor("edison") button := gpio.NewGroveButtonDriver(e, "button", "2") work := func() { gobot.On(button.Event(gpio.Push), func(data interface{}) { fmt.Println("On!") }) gobot.On(button.Event(gpio.Release), func(data interface{}) { fmt.Println("Off!") }) } robot := gobot.NewRobot("bot", []gobot.Connection{e}, []gobot.Device{button}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone") button := gpio.NewMakeyButtonDriver(beagleboneAdaptor, "button", "P8_9") work := func() { gobot.On(button.Event("push"), func(data interface{}) { fmt.Println("button pressed") }) gobot.On(button.Event("release"), func(data interface{}) { fmt.Println("button released") }) } robot := gobot.NewRobot("makeyBot", []gobot.Connection{beagleboneAdaptor}, []gobot.Device{button}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() board := edison.NewEdisonAdaptor("edison") button = gpio.NewGroveButtonDriver(board, "button", "2") blue = gpio.NewGroveLedDriver(board, "blue", "3") green = gpio.NewGroveLedDriver(board, "green", "4") work := func() { Reset() gobot.On(button.Event(gpio.Push), func(data interface{}) { TurnOff() fmt.Println("On!") blue.On() }) gobot.On(button.Event(gpio.Release), func(data interface{}) { Reset() }) } robot := gobot.NewRobot("airlock", []gobot.Connection{board}, []gobot.Device{button, blue, green}, work, ) gbot.AddRobot(robot) gbot.Start() }
func (ia *AI) obstacle() { d := new(Data) ch := make(chan bool) gobot.On(ia.buttonObstacle.Event("push"), func(data interface{}) { d.startPushingTime = time.Now() log.Println("Le bouton poussoir est enfonce") ia.sendMessageAI(rocproto.AiCodes_OBSTACLE) select { case <-time.After(time.Second * 3): ia.toggle(true) log.Println("Ai control") ia.unlockRobot() log.Println("Ai releasing Control") ia.toggle(false) break case <-ch: fmt.Println("c'etait un obstacle passager, retour a la normale") break } }) gobot.On(ia.buttonObstacle.Event("release"), func(data interface{}) { log.Println("Button poussoir est relache") ia.sendMessageAI(rocproto.AiCodes_N_OBSTACLE) ch <- true }) }
func main() { gbot := gobot.NewGobot() sparkCore := spark.NewSparkCoreAdaptor("spark", "device_id", "access_token") led := gpio.NewLedDriver(sparkCore, "led", "D7") button := gpio.NewButtonDriver(sparkCore, "button", "D5") work := func() { gobot.On(button.Event("push"), func(data interface{}) { led.On() }) gobot.On(button.Event("release"), func(data interface{}) { led.Off() }) } robot := gobot.NewRobot("spark", []gobot.Connection{sparkCore}, []gobot.Device{button, led}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() api.NewAPI(gbot).Start() pebbleAdaptor := pebble.NewPebbleAdaptor("pebble") pebbleDriver := pebble.NewPebbleDriver(pebbleAdaptor, "pebble") work := func() { pebbleDriver.SendNotification("Hello Pebble!") gobot.On(pebbleDriver.Event("button"), func(data interface{}) { fmt.Println("Button pushed: " + data.(string)) }) gobot.On(pebbleDriver.Event("tap"), func(data interface{}) { fmt.Println("Tap event detected") }) } robot := gobot.NewRobot("pebble", []gobot.Connection{pebbleAdaptor}, []gobot.Device{pebbleDriver}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() e := edison.NewEdisonAdaptor("edison") button := gpio.NewButtonDriver(e, "myButton", "2") led := gpio.NewLedDriver(e, "myLed", "4") work := func() { gobot.On(button.Event("push"), func(data interface{}) { led.On() }) gobot.On(button.Event("release"), func(data interface{}) { led.Off() }) } robot := gobot.NewRobot("buttonBot", []gobot.Connection{e}, []gobot.Device{led, button}, work, ) gbot.AddRobot(robot) gbot.Start() }
func TestWiichuckDriverUpdateButtons(t *testing.T) { //when data["c"] is 0 chann := make(chan bool) wii := initTestWiichuckDriver() wii.data["c"] = 0 wii.updateButtons() gobot.On(wii.Event(C), func(data interface{}) { gobot.Assert(t, true, data) chann <- true }) <-chann //when data["z"] is 0 chann = make(chan bool) wii = initTestWiichuckDriver() wii.data["z"] = 0 wii.updateButtons() gobot.On(wii.Event(Z), func(data interface{}) { gobot.Assert(t, true, data) chann <- true }) <-chann }
func main() { gbot := gobot.NewGobot() // create a ardrone adapter aAdapter := ardrone.NewArdroneAdaptor("Drone") // create a leap adaptor to connect to the leap motion via web socket. lAdapter := leap.NewLeapMotionAdaptor("leap", "127.0.0.1:6437") c := leapdrone.NewController(lAdapter, aAdapter) // implement leap worker leapWorker := func() { // NOTE: leap motion driver only add message event to it. gobot.On(c.LDriver.Event("message"), func(data interface{}) { lp := data.(leap.Frame) for _, v := range lp.Hands { // XXX: catch the first hand id and ignore other annoying hands hand := lb.NewHand(v, 200) if hand.IsForward() { fmt.Printf("moving forward\n") } if hand.IsBackward() { fmt.Printf("moving backward\n") } if hand.IsRight() { fmt.Printf("moving right\n") } if hand.IsLeft() { fmt.Printf("moving left\n") } if hand.IsUpward() { fmt.Printf("moving up\n") } if hand.IsDownward() { fmt.Printf("moving down\n") } continue } }) } // implement ARDrone worker droneWorker := func() { c.ADriver.TakeOff() gobot.On(c.ADriver.Event("flying"), func(data interface{}) { gobot.After(3*time.Second, func() { c.ADriver.Land() }) }) } // add a leap robot to gobot gbot.AddRobot(c.LeapRobot(leapWorker)) // add a ardrone robot to gobot // TODO: temporarily disable drone robot. // gbot.AddRobot(c.DroneRobot(droneWorker)) _ = droneWorker // start gbot.Start() }
func main() { gbot := gobot.NewGobot() board := firmata.NewFirmataAdaptor("arduino", os.Args[1]) // digital devices button := gpio.NewButtonDriver(board, "button", "2") blue := gpio.NewLedDriver(board, "blue", "3") work := func() { gobot.On(button.Event(gpio.Push), func(data interface{}) { fmt.Println("On!") blue.On() }) gobot.On(button.Event(gpio.Release), func(data interface{}) { fmt.Println("Off!") blue.Off() }) } robot := gobot.NewRobot("airlock", []gobot.Connection{board}, []gobot.Device{button, blue}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0") wiichuck := i2c.NewWiichuckDriver(firmataAdaptor, "wiichuck") work := func() { gobot.On(wiichuck.Event("joystick"), func(data interface{}) { fmt.Println("joystick", data) }) gobot.On(wiichuck.Event("c"), func(data interface{}) { fmt.Println("c") }) gobot.On(wiichuck.Event("z"), func(data interface{}) { fmt.Println("z") }) gobot.On(wiichuck.Event("error"), func(data interface{}) { fmt.Println("Wiichuck error:", data) }) } robot := gobot.NewRobot("chuck", []gobot.Connection{firmataAdaptor}, []gobot.Device{wiichuck}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() e := edison.NewEdisonAdaptor("edison") touch := gpio.NewGroveTouchDriver(e, "touch", "2") work := func() { gobot.On(touch.Event(gpio.Push), func(data interface{}) { fmt.Println("On!") }) gobot.On(touch.Event(gpio.Release), func(data interface{}) { fmt.Println("Off!") }) } robot := gobot.NewRobot("blinkBot", []gobot.Connection{e}, []gobot.Device{touch}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0") button := gpio.NewMakeyButtonDriver(firmataAdaptor, "button", "2") led := gpio.NewLedDriver(firmataAdaptor, "led", "13") work := func() { gobot.On(button.Event("push"), func(data interface{}) { led.On() }) gobot.On(button.Event("release"), func(data interface{}) { led.Off() }) } robot := gobot.NewRobot("makeyBot", []gobot.Connection{firmataAdaptor}, []gobot.Device{button, led}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() chipAdaptor := chip.NewChipAdaptor("chip") button := gpio.NewButtonDriver(chipAdaptor, "button", "XIO-P6") led := gpio.NewLedDriver(chipAdaptor, "led", "XIO-P7") work := func() { gobot.On(button.Event("push"), func(data interface{}) { led.On() }) gobot.On(button.Event("release"), func(data interface{}) { led.Off() }) } robot := gobot.NewRobot("buttonBot", []gobot.Connection{chipAdaptor}, []gobot.Device{button, led}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() e := edison.NewEdisonAdaptor("edison") m := mqtt.NewMqttAdaptor("mqtt", "tcp://192.168.0.90:1883", "pump") lever := gpio.NewButtonDriver(e, "lever", "2") fault := gpio.NewButtonDriver(e, "fault", "4") pump := gpio.NewDirectPinDriver(e, "pump", "13") work := func() { dgram := url.Values{ "name": {"Four"}, "dispenser_id": {"4"}, "drink_id": {"0"}, "event": {"online"}, "details": {"dispenser"}, } pumping := false served := byte(0) m.On("startPump", func(data []byte) { if !pumping { pumping = true pump.DigitalWrite(1) served++ dgram.Set("event", "online") dgram.Set("drink_id", fmt.Sprintf("%v", served)) m.Publish("pumped", []byte(dgram.Encode())) gobot.After(2*time.Second, func() { pump.DigitalWrite(0) pumping = false }) } }) gobot.On(lever.Event("push"), func(data interface{}) { m.Publish("pump", []byte{}) }) m.On("startFault", func(data []byte) { dgram.Set("event", "error") m.Publish("fault", []byte(dgram.Encode())) }) gobot.On(fault.Event("push"), func(data interface{}) { m.Publish("startFault", []byte{}) }) } gbot.AddRobot(gobot.NewRobot("brewmachine", []gobot.Connection{e, m}, []gobot.Device{lever, fault, pump}, work, )) gbot.Start() }
func main() { flag.Parse() // Initialize Intel Edison edisonAdaptor := edison.NewEdisonAdaptor("edison") edisonAdaptor.Connect() lightSensor := gpio.NewGroveLightSensorDriver(edisonAdaptor, "light", *sensorLightPin, *sensorPollingInterval) lightSensor.Start() gobot.On(lightSensor.Event("data"), func(data interface{}) { raw := float64(data.(int)) // convert to lux resistance := (1023.0 - raw) * 10.0 / raw * 15.0 light = 10000.0 / math.Pow(resistance, 4.0/3.0) lightUpdated = time.Now() log.Debugln("illuminance: ", light) }) soundSensor := gpio.NewGroveSoundSensorDriver(edisonAdaptor, "sound", *sensorSoundPin, *sensorPollingInterval) soundSensor.Start() gobot.On(soundSensor.Event("data"), func(data interface{}) { sound = float64(data.(int)) soundUpdated = time.Now() log.Debugln("sound level: ", sound) }) tempSensor := gpio.NewGroveTemperatureSensorDriver(edisonAdaptor, "temp", *sensorTempPin, *sensorPollingInterval) tempSensor.Start() gobot.On(tempSensor.Event("data"), func(data interface{}) { celsius = data.(float64) fahrenheit = celsius*1.8 + 32 tempUpdated = time.Now() log.Debugln("temperature: ", celsius) }) // Initialize prometheus exporter exporter := NewExporter() prometheus.MustRegister(exporter) log.Infof("Listening on: %s", *listenAddress) http.Handle(*metricPath, prometheus.Handler()) http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) { w.Write([]byte(` <html> <head> <title>IoT Edison exporter</title> </head> <body> <h1>Prometheus exporter for sensor metrics from Intel Edison</h1> <p><a href='` + *metricPath + `'>Metrics</a></p> </body> </html> `)) }) log.Fatal(http.ListenAndServe(*listenAddress, nil)) }
func main() { gbot := gobot.NewGobot() bleAdaptor := ble.NewBLEAdaptor("ble", os.Args[1]) drone := ble.NewBLEMinidroneDriver(bleAdaptor, "drone") work := func() { gobot.On(drone.Event("battery"), func(data interface{}) { fmt.Printf("battery: %d\n", data) }) gobot.On(drone.Event("status"), func(data interface{}) { fmt.Printf("status: %d\n", data) }) gobot.On(drone.Event("flying"), func(data interface{}) { fmt.Println("flying!") gobot.After(5*time.Second, func() { fmt.Println("forwards...") drone.Forward(10) }) gobot.After(10*time.Second, func() { fmt.Println("backwards...") drone.Backward(10) }) gobot.After(15*time.Second, func() { fmt.Println("right...") drone.Right(10) }) gobot.After(20*time.Second, func() { fmt.Println("left...") drone.Left(10) }) gobot.After(25*time.Second, func() { fmt.Println("landing...") drone.Land() }) }) gobot.On(drone.Event("landed"), func(data interface{}) { fmt.Println("landed.") }) drone.TakeOff() } robot := gobot.NewRobot("minidrone", []gobot.Connection{bleAdaptor}, []gobot.Device{drone}, work, ) gbot.AddRobot(robot) gbot.Start() }
func TestWiichuckDriverUpdateJoystick(t *testing.T) { chann := make(chan bool) wii := initTestWiichuckDriver() // First pass wii.data["sx"] = 40 wii.data["sy"] = 55 wii.joystick["sx_origin"] = 1 wii.joystick["sy_origin"] = 5 expectedData := map[string]float64{ "x": float64(39), "y": float64(50), } gobot.On(wii.Event(Joystick), func(data interface{}) { gobottest.Assert(t, data, expectedData) chann <- true }) wii.updateJoystick() select { case <-chann: case <-time.After(10 * time.Second): t.Errorf("Did not recieve 'Joystick' event") } //// Second pass wii = initTestWiichuckDriver() wii.data["sx"] = 178 wii.data["sy"] = 34 wii.joystick["sx_origin"] = 14 wii.joystick["sy_origin"] = 27 expectedData = map[string]float64{ "x": float64(164), "y": float64(7), } gobot.On(wii.Event(Joystick), func(data interface{}) { gobottest.Assert(t, data, expectedData) chann <- true }) wii.updateJoystick() select { case <-chann: case <-time.After(10 * time.Second): t.Errorf("Did not recieve 'Joystick' event") } }
func main() { gbot := gobot.NewGobot() a := api.NewAPI(gbot) a.Start() board := firmata.NewFirmataAdaptor("arduino", os.Args[1]) // digital devices button = gpio.NewButtonDriver(board, "button", "2") blue = gpio.NewLedDriver(board, "blue", "3") green = gpio.NewLedDriver(board, "green", "4") buzzer = gpio.NewGroveBuzzerDriver(board, "buzzer", "7") touch = gpio.NewButtonDriver(board, "touch", "8") // analog devices light = gpio.NewAnalogSensorDriver(board, "light", "0") work := func() { Reset() gobot.On(button.Event(gpio.Push), func(data interface{}) { TurnOff() fmt.Println("On!") blue.On() }) gobot.On(button.Event(gpio.Release), func(data interface{}) { Reset() }) gobot.On(touch.Event(gpio.Push), func(data interface{}) { Doorbell() }) gobot.On(light.Event("data"), func(data interface{}) { fmt.Println("light", data) }) } robot := gobot.NewRobot("airlock", []gobot.Connection{board}, []gobot.Device{button, blue, green, buzzer, touch, light}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { joystickAdaptor := new(gobotJoystick.JoystickAdaptor) joystickAdaptor.Name = "x52" joystickAdaptor.Params = map[string]interface{}{ "config": "./saitek-x52.json", } joystick := gobotJoystick.NewJoystick(joystickAdaptor) joystick.Name = "x52" spheroAdaptor := new(gobotSphero.SpheroAdaptor) spheroAdaptor.Name = "Sphero" spheroAdaptor.Port = "/dev/tty.Sphero-PWG-RN-SPP" sphero := gobotSphero.NewSphero(spheroAdaptor) sphero.Name = "Sphero" var ( x, y int direction uint16 speed uint8 ) x = 1 y = 1 direction = 0 speed = 0 work := func() { gobot.On(joystick.Events["right_x"], func(data interface{}) { x = int(data.(int16)) }) gobot.On(joystick.Events["right_y"], func(data interface{}) { y = int(data.(int16)) }) gobot.Every("0.01s", func() { direction = Angle(x, y) speed = uint8(math.Sqrt(float64(x*x+y*y)) / 128) //255 fmt.Println(x, y, speed, direction) sphero.Roll(speed, direction) }) } robot := gobot.Robot{ Connections: []gobot.Connection{joystickAdaptor, spheroAdaptor}, Devices: []gobot.Device{joystick, sphero}, Work: work, } robot.Start() }
func main() { gbot := gobot.NewGobot() firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0") servo1 := gpio.NewServoDriver(firmataAdaptor, "servo", "5") servo2 := gpio.NewServoDriver(firmataAdaptor, "servo", "3") leapAdaptor := leap.NewLeapMotionAdaptor("leap", "127.0.0.1:6437") leapDriver := leap.NewLeapMotionDriver(leapAdaptor, "leap") work := func() { x := 90.0 z := 90.0 gobot.On(leapDriver.Events["Message"], func(data interface{}) { if len(data.(leap.Frame).Hands) > 0 { hand := data.(leap.Frame).Hands[0] x = gobot.ToScale(gobot.FromScale(hand.X(), -300, 300), 30, 150) z = gobot.ToScale(gobot.FromScale(hand.Z(), -300, 300), 30, 150) } }) gobot.Every(10*time.Millisecond, func() { servo1.Move(uint8(x)) servo2.Move(uint8(z)) fmt.Println("Current Angle: ", servo1.CurrentAngle, ",", servo2.CurrentAngle) }) } gbot.Robots = append(gbot.Robots, gobot.NewRobot("pwmBot", []gobot.Connection{firmataAdaptor, leapAdaptor}, []gobot.Device{servo1, servo2, leapDriver}, work)) gbot.Start() }
func (a *API) robotDeviceEvent(res http.ResponseWriter, req *http.Request) { f, _ := res.(http.Flusher) c, _ := res.(http.CloseNotifier) dataChan := make(chan string) closer := c.CloseNotify() res.Header().Set("Content-Type", "text/event-stream") res.Header().Set("Cache-Control", "no-cache") res.Header().Set("Connection", "keep-alive") if event := a.gobot.Robot(req.URL.Query().Get(":robot")). Device(req.URL.Query().Get(":device")).(gobot.Eventer). Event(req.URL.Query().Get(":event")); event != nil { gobot.On(event, func(data interface{}) { d, _ := json.Marshal(data) dataChan <- string(d) }) for { select { case data := <-dataChan: fmt.Fprintf(res, "data: %v\n\n", data) f.Flush() case <-closer: log.Println("Closing connection") return } } } else { a.writeJSON(map[string]interface{}{ "error": "No Event found with the name " + req.URL.Query().Get(":event"), }, res) } }
func main() { gbot := gobot.NewGobot() keys := keyboard.NewKeyboardDriver("keyboard") work := func() { gobot.On(keys.Event("key"), func(data interface{}) { key := data.(keyboard.KeyEvent) if key.Key == keyboard.A { fmt.Println("A pressed!") } else { fmt.Println("keyboard event!", key, key.Char) } }) } robot := gobot.NewRobot("keyboardbot", []gobot.Connection{}, []gobot.Device{keys}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() adaptor := sphero.NewSpheroAdaptor("Sphero", "/dev/rfcomm0") spheroDriver := sphero.NewSpheroDriver(adaptor, "sphero") work := func() { gobot.On(spheroDriver.Event("collision"), func(data interface{}) { fmt.Println("Collision Detected!") }) gobot.Every(3*time.Second, func() { spheroDriver.Roll(30, uint16(gobot.Rand(360))) }) gobot.Every(1*time.Second, func() { r := uint8(gobot.Rand(255)) g := uint8(gobot.Rand(255)) b := uint8(gobot.Rand(255)) spheroDriver.SetRGB(r, g, b) }) } robot := gobot.NewRobot("sphero", []gobot.Connection{adaptor}, []gobot.Device{spheroDriver}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() a := api.NewAPI(gbot) a.Port = "8080" a.Start() pebbleAdaptor := pebble.NewPebbleAdaptor("pebble") pebbleDriver := pebble.NewPebbleDriver(pebbleAdaptor, "pebble") work := func() { gobot.On(pebbleDriver.Event("accel"), func(data interface{}) { fmt.Println(data.(string)) }) } robot := gobot.NewRobot("pebble", []gobot.Connection{pebbleAdaptor}, []gobot.Device{pebbleDriver}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() bebopAdaptor := bebop.NewBebopAdaptor("Drone") drone := bebop.NewBebopDriver(bebopAdaptor, "Drone") work := func() { gobot.On(drone.Event("flying"), func(data interface{}) { gobot.After(3*time.Second, func() { drone.Land() }) }) drone.HullProtection(true) drone.TakeOff() } robot := gobot.NewRobot("drone", []gobot.Connection{bebopAdaptor}, []gobot.Device{drone}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() edisonAdaptor := edison.NewEdisonAdaptor("edison") blinkm := i2c.NewBlinkMDriver(edisonAdaptor, "blinkm") sensor := gpio.NewAnalogSensorDriver(edisonAdaptor, "sensor", "2") work := func() { gobot.On(sensor.Event("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) blinkm.Rgb(0, brightness, 0) }) } robot := gobot.NewRobot("sensorBot", []gobot.Connection{edisonAdaptor}, []gobot.Device{blinkm, sensor}, work, ) gbot.AddRobot(robot) gbot.Start() }