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() natsAdaptor := nats.NewNatsAdaptorWithAuth("nats", "localhost:4222", 1234) work := func() { natsAdaptor.On("hello", func(data []byte) { fmt.Println("hello") }) natsAdaptor.On("hola", func(data []byte) { fmt.Println("hola") }) data := []byte("o") gobot.Every(1*time.Second, func() { natsAdaptor.Publish("hello", data) }) gobot.Every(5*time.Second, func() { natsAdaptor.Publish("hola", data) }) } robot := gobot.NewRobot("natsBot", []gobot.Connection{natsAdaptor}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() bleAdaptor := ble.NewBLEClientAdaptor("ble", os.Args[1]) ollie := ble.NewSpheroOllieDriver(bleAdaptor, "ollie") work := func() { gobot.Every(1*time.Second, func() { r := uint8(gobot.Rand(255)) g := uint8(gobot.Rand(255)) b := uint8(gobot.Rand(255)) ollie.SetRGB(r, g, b) }) gobot.Every(3*time.Second, func() { ollie.Roll(40, uint16(gobot.Rand(360))) }) } robot := gobot.NewRobot("ollieBot", []gobot.Connection{bleAdaptor}, []gobot.Device{ollie}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() mqttAdaptor := mqtt.NewMqttAdaptor("server", "tcp://test.mosquitto.org:1883", "blinker") firmataAdaptor := firmata.NewFirmataAdaptor("arduino", "/dev/ttyACM0") led := gpio.NewLedDriver(firmataAdaptor, "led", "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, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() mqttAdaptor := mqtt.NewMqttAdaptor("server", "tcp://test.mosquitto.org:1883", "pinger") work := func() { mqttAdaptor.On("hello", func(data []byte) { fmt.Println("hello") }) mqttAdaptor.On("hola", func(data []byte) { fmt.Println("hola") }) data := []byte("o") gobot.Every(1*time.Second, func() { mqttAdaptor.Publish("hello", data) }) gobot.Every(5*time.Second, func() { mqttAdaptor.Publish("hola", data) }) } robot := gobot.NewRobot("mqttBot", []gobot.Connection{mqttAdaptor}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() e := edison.NewEdisonAdaptor("edison") board_led := gpio.NewLedDriver(e, "led", "13") red_led := gpio.NewLedDriver(e, "led", "3") green_led := gpio.NewLedDriver(e, "led", "2") buzzer := gpio.NewBuzzerDriver(e, "buzzer", "4") // Blink the Board LED board_blink_work := func() { gobot.Every(10*time.Second, func() { board_led.Toggle() }) } // Ring the buzzer buzzer_work := func() { gobot.Every(4*time.Second, func() { buzzer.Tone(gpio.G5, gpio.Eighth) }) } board_blink_bot := gobot.NewRobot("Board LED", []gobot.Connection{e}, []gobot.Device{board_led}, board_blink_work, ) buzz_bot := gobot.NewRobot("buzzBot", []gobot.Connection{e}, []gobot.Device{buzzer}, buzzer_work, ) red_blink_bot := gobot.NewRobot("Red LED", []gobot.Connection{e}, []gobot.Device{red_led}, ) green_blink_bot := gobot.NewRobot("Green LED", []gobot.Connection{e}, []gobot.Device{green_led}, ) gbot.AddRobot(board_blink_bot) gbot.AddRobot(green_blink_bot) gbot.AddRobot(red_blink_bot) gbot.AddRobot(buzz_bot) a := api.NewAPI(gbot) a.Debug() a.Start() gbot.Start() }
func main() { var robots []gobot.Robot spheros := []string{ "127.0.0.1:4560", "127.0.0.1:4561", "127.0.0.1:4562", "127.0.0.1:4563", } for s := range spheros { spheroAdaptor := new(gobotSphero.SpheroAdaptor) spheroAdaptor.Name = "Sphero" spheroAdaptor.Port = spheros[s] sphero := gobotSphero.NewSphero(spheroAdaptor) sphero.Name = "Sphero" + spheros[s] sphero.Interval = "0.5s" work := func() { conway := new(conway) conway.sphero = sphero conway.birth() go func() { for { gobot.On(sphero.Events["Collision"]) conway.contact() } }() gobot.Every("3s", func() { if conway.alive == true { conway.movement() } }) gobot.Every("10s", func() { if conway.alive == true { conway.birthday() } }) } robots = append(robots, gobot.Robot{Connections: []interface{}{spheroAdaptor}, Devices: []interface{}{sphero}, Work: work}) } gobot.Work(robots) }
func main() { spheroAdaptor := new(gobotSphero.SpheroAdaptor) spheroAdaptor.Name = "Sphero" spheroAdaptor.Port = "127.0.0.1:4560" sphero := gobotSphero.NewSphero(spheroAdaptor) sphero.Name = "Sphero" connections := []interface{}{ spheroAdaptor, } devices := []interface{}{ sphero, } work := func() { sphero.Stop() go func() { for { gobot.On(sphero.Events["Collision"]) fmt.Println("Collision Detected!") } }() gobot.Every("2s", func() { dir := uint16(gobot.Random(0, 360)) sphero.Roll(100, dir) }) gobot.Every("3s", func() { r := uint8(gobot.Random(0, 255)) g := uint8(gobot.Random(0, 255)) b := uint8(gobot.Random(0, 255)) sphero.SetRGB(r, g, b) }) } robot := gobot.Robot{ Connections: connections, Devices: devices, Work: work, } robot.Start() }
func main() { gbot := gobot.NewGobot() digisparkAdaptor := digispark.NewDigisparkAdaptor("digispark") led := gpio.NewLedDriver(digisparkAdaptor, "led", "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, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0") motor := gpio.NewMotorDriver(firmataAdaptor, "motor", "3") work := func() { speed := byte(0) fadeAmount := byte(15) gobot.Every(100*time.Millisecond, func() { motor.Speed(speed) speed = speed + fadeAmount if speed == 0 || speed == 255 { fadeAmount = -fadeAmount } }) } robot := gobot.NewRobot("motorBot", []gobot.Connection{firmataAdaptor}, []gobot.Device{motor}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() board := edison.NewEdisonAdaptor("edison") accel := i2c.NewGroveAccelerometerDriver(board, "accel") work := func() { gobot.Every(500*time.Millisecond, func() { if x, y, z, err := accel.XYZ(); err == nil { fmt.Println(x, y, z) fmt.Println(accel.Acceleration(x, y, z)) } else { fmt.Println(err) } }) } robot := gobot.NewRobot("accelBot", []gobot.Connection{board}, []gobot.Device{accel}, work, ) gbot.AddRobot(robot) gbot.Start() }
func (sd *SpheroDriver) StartDriver() { sd.ConfigureCollisionDetection() gobot.Every(sd.Interval, func() { sd.handleMessageEvents() }) }
func main() { gbot := gobot.NewGobot() e := edison.NewEdisonAdaptor("edison") led := gpio.NewRgbLedDriver(e, "led", "3", "5", "6") work := func() { gobot.Every(1*time.Second, func() { r := uint8(gobot.Rand(255)) g := uint8(gobot.Rand(255)) b := uint8(gobot.Rand(255)) led.SetRGB(r, g, b) }) } robot := gobot.NewRobot("rgbBot", []gobot.Connection{e}, []gobot.Device{led}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() e := joule.NewJouleAdaptor("joule") blinkm := i2c.NewBlinkMDriver(e, "blinkm") work := func() { gobot.Every(3*time.Second, func() { r := byte(gobot.Rand(255)) g := byte(gobot.Rand(255)) b := byte(gobot.Rand(255)) blinkm.Rgb(r, g, b) color, _ := blinkm.Color() fmt.Println("color", color) }) } robot := gobot.NewRobot("blinkmBot", []gobot.Connection{e}, []gobot.Device{blinkm}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { beaglebone := new(gobotBeaglebone.Beaglebone) beaglebone.Name = "beaglebone" led := gobotGPIO.NewLed(beaglebone) led.Name = "led" led.Pin = "P9_14" work := func() { brightness := uint8(0) fade_amount := uint8(5) gobot.Every("0.1s", func() { led.Brightness(brightness) brightness = brightness + fade_amount if brightness == 0 || brightness == 255 { fade_amount = -fade_amount } }) } robot := gobot.Robot{ Connections: []gobot.Connection{beaglebone}, Devices: []gobot.Device{led}, 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 main() { gbot := gobot.NewGobot() r := raspi.NewRaspiAdaptor("raspi") led := gpio.NewLedDriver(r, "led", "12") work := func() { current := uint8(0) change := uint8(5) gobot.Every(30*time.Millisecond, func() { led.Brightness(current) current += change if current == 0 || current == 255 { change = -change } }) } robot := gobot.NewRobot("blinkBot", []gobot.Connection{r}, []gobot.Device{led}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0") work := func() { gobot.Every(1*time.Second, func() { val, err := firmataAdaptor.AnalogRead("0") if err != nil { fmt.Println(err) return } voltage := (float64(val) * 5) / 1024 // if using 3.3V replace 5 with 3.3 tempC := (voltage - 0.5) * 100 tempF := (tempC * 9 / 5) + 32 fmt.Printf("%.2f°C\n", tempC) fmt.Printf("%.2f°F\n", tempF) }) } robot := gobot.NewRobot("sensorBot", []gobot.Connection{firmataAdaptor}, []gobot.Device{}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { deviceName := flag.String("device", "", "path to Sphero device") flag.Parse() gbot := gobot.NewGobot() adaptor := sphero.NewSpheroAdaptor("sphero", *deviceName) driver := sphero.NewSpheroDriver(adaptor, "sphero") work := func() { gobot.Every(3*time.Second, func() { driver.Roll(30, uint16(gobot.Rand(360))) }) } robot := gobot.NewRobot("sphero", []gobot.Connection{adaptor}, []gobot.Device{driver}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { master := gobot.NewGobot() spheros := map[string]string{ "Sphero-BPO": "/dev/rfcomm0", } for name, port := range spheros { spheroAdaptor := sphero.NewSpheroAdaptor("sphero", port) spheroDriver := sphero.NewSpheroDriver(spheroAdaptor, "sphero") work := func() { spheroDriver.SetRGB(uint8(255), uint8(0), uint8(0)) } master.Robots = append(master.Robots, gobot.NewRobot(name, []gobot.Connection{spheroAdaptor}, []gobot.Device{spheroDriver}, work)) } master.Robots = append(master.Robots, gobot.NewRobot( "", nil, nil, func() { gobot.Every(1*time.Second, func() { gobot.Call(master.Robot("Sphero-BPO").Device("sphero").Driver, "SetRGB", uint8(gobot.Rand(255)), uint8(gobot.Rand(255)), uint8(gobot.Rand(255))) }) }, )) master.Start() }
func main() { gbot := gobot.NewGobot() firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0") mma7660 := i2c.NewMMA7660Driver(firmataAdaptor, "mma7660") work := func() { gobot.Every(500*time.Millisecond, func() { if x, y, z, err := mma7660.XYZ(); err == nil { fmt.Println(x, y, z) fmt.Println(mma7660.Acceleration(x, y, z)) } else { fmt.Println(err) } }) } robot := gobot.NewRobot("mma76602Bot", []gobot.Connection{firmataAdaptor}, []gobot.Device{mma7660}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() adaptor := sphero.NewSpheroAdaptor("sphero", "/dev/tty.Sphero-BRB-AMP-SPP") driver := sphero.NewSpheroDriver(adaptor, "sphero") work := func() { gobot.Every(100*time.Millisecond, func() { driver.SetRGB( uint8(gobot.Rand(255)), uint8(gobot.Rand(255)), uint8(gobot.Rand(255))) }) } robot := gobot.NewRobot("sphero", []gobot.Connection{adaptor}, []gobot.Device{driver}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { beaglebone := new(gobotBeaglebone.Beaglebone) beaglebone.Name = "beaglebone" sensor := gobotGPIO.NewAnalogSensor(beaglebone) sensor.Name = "sensor" sensor.Pin = "P9_33" led := gobotGPIO.NewLed(beaglebone) led.Name = "led" led.Pin = "P9_14" work := func() { gobot.Every("0.1s", func() { val := sensor.Read() brightness := uint8(gobotGPIO.ToPwm(val)) fmt.Println("sensor", val) fmt.Println("brightness", brightness) led.Brightness(brightness) }) } robot := gobot.Robot{ Connections: []gobot.Connection{beaglebone}, Devices: []gobot.Device{sensor, led}, Work: work, } robot.Start() }
func main() { gbot := gobot.NewGobot() firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0") blinkm := i2c.NewBlinkMDriver(firmataAdaptor, "blinkm") work := func() { gobot.Every(3*time.Second, func() { r := byte(gobot.Rand(255)) g := byte(gobot.Rand(255)) b := byte(gobot.Rand(255)) blinkm.Rgb(r, g, b) fmt.Println("color", blinkm.Color()) }) } robot := gobot.NewRobot("blinkmBot", []gobot.Connection{firmataAdaptor}, []gobot.Device{blinkm}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() firmataAdaptor := firmata.NewFirmataAdaptor("myFirmata", "/dev/ttyACM0") pin := gpio.NewDirectPinDriver(firmataAdaptor, "pin", "13") work := func() { level := byte(1) gobot.Every(1*time.Second, func() { pin.DigitalWrite(level) if level == 1 { level = 0 } else { level = 1 } }) } robot := gobot.NewRobot("pinBot", []gobot.Connection{firmataAdaptor}, []gobot.Device{pin}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() adaptor := sphero.NewSpheroAdaptor("Sphero", "/dev/rfcomm0") board := edison.NewEdisonAdaptor("edison") spheroDriver := sphero.NewSpheroDriver(adaptor, "sphero") sensorAccel := i2c.NewGroveAccelerometerDriver(board, "accel") work := func() { gobot.Every(time.Millisecond*20, func() { if x, y, z, err := sensorAccel.XYZ(); err == nil { degree := math.Sin(y/x) * 360 spheroDriver.Roll(uint8(100+z), uint16(degree)) } }) } robot := gobot.NewRobot("sphero", []gobot.Connection{adaptor, board}, []gobot.Device{sensorAccel, spheroDriver}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone") led := gpio.NewLedDriver(beagleboneAdaptor, "led", "P9_14") work := func() { brightness := uint8(0) fadeAmount := uint8(5) 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{beagleboneAdaptor}, []gobot.Device{led}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0") red := gpio.NewLedDriver(firmataAdaptor, "red", "7") green := gpio.NewLedDriver(firmataAdaptor, "green", "6") blue := gpio.NewLedDriver(firmataAdaptor, "blue", "5") work := func() { checkTravis(gbot.Robot("travis")) gobot.Every(10*time.Second, func() { checkTravis(gbot.Robot("travis")) }) } robot := gobot.NewRobot("travis", []gobot.Connection{firmataAdaptor}, []gobot.Device{red, green, blue}, work, ) gbot.AddRobot(robot) gbot.Start() }
// Demos the Gobot Every function, which provides a way // to trigger recurring functionality. func blinkLedOverAndOver(gbot *gobot.Gobot) { // Create an instance of our chosen adapter type // and pass it to the LED driver. The names given here // are used in the management functionality. beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone") led := gpio.NewLedDriver(beagleboneAdaptor, "led", "P9_15") // Robots in the Gobot colletion run a "work" function // when they fire work := func() { gobot.Every(1*time.Second, func() { led.Toggle() }) } // A Robot is a board or device, and is one of the things managed by a Gobot. // Here we make one with the adaptor and led objects we made above. // The constructor creates a new named robot, provided a connection and a device // which will map to something like a GPIO pin. // A Robot can be composed of as many Connections and Devices as you like, // meaning that you can create something out of a group of supported hardware pieces // and treat it in code as a single logical unit. robot := gobot.NewRobot("blinkBot", []gobot.Connection{beagleboneAdaptor}, []gobot.Device{led}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone") led := gpio.NewDirectPinDriver(beagleboneAdaptor, "led", "P8_10") button := gpio.NewDirectPinDriver(beagleboneAdaptor, "button", "P8_9") work := func() { gobot.Every(500*time.Millisecond, func() { if button.DigitalRead() == 1 { led.DigitalWrite(1) } else { led.DigitalWrite(0) } }) } robot := gobot.NewRobot("pinBot", []gobot.Connection{beagleboneAdaptor}, []gobot.Device{led}, work, ) gbot.AddRobot(robot) gbot.Start() }