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() }
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") green = gpio.NewLedDriver(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() }
// NewMatrixCube creates a new matrix based cube. func NewMatrixCube(conn gpio.DigitalWriter, config MatrixConfig) (*MatrixCube, error) { rows := []*gpio.LedDriver{} for _, elem := range config.Rows { rows = append(rows, gpio.NewLedDriver(conn, "led", strconv.FormatInt(int64(elem), 10))) } cols := []*gpio.LedDriver{} for _, elem := range config.Cols { cols = append(cols, gpio.NewLedDriver(conn, "led", strconv.FormatInt(int64(elem), 10))) } dim := make([][][]MatrixPoint, len(config.Cube)) for i, tmp1 := range config.Cube { dim[i] = make([][]MatrixPoint, len(tmp1)) for j, tmp2 := range tmp1 { dim[i][j] = make([]MatrixPoint, len(tmp2)) for k := range tmp2 { dim[i][j][k] = MatrixPoint{rows[config.Cube[i][j][k][0]], cols[config.Cube[i][j][k][1]]} } } } return &MatrixCube{ dim: dim, rows: rows, cols: cols, }, nil }
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 blink(colors chan int) { //initialize robot friend gbot := gobot.NewGobot() firmataAdaptor := firmata.NewFirmataAdaptor("arduino", "/dev/cu.usbmodem1421") led_g := gpio.NewLedDriver(firmataAdaptor, "led", "13") led_r := gpio.NewLedDriver(firmataAdaptor, "led", "12") led_b := gpio.NewLedDriver(firmataAdaptor, "led", "11") led_rainbow := gpio.NewLedDriver(firmataAdaptor, "led", "10") work := func() { gobot.Every(1*time.Millisecond, func() { color, alive := <-colors if !alive { panic("Quittin'") } switch color { case 0: led_rainbow.Off() led_g.Toggle() case 1: led_rainbow.Off() led_b.Toggle() case 2: led_rainbow.Off() led_r.Toggle() case 3: led_g.Off() led_b.Off() led_r.Off() led_rainbow.On() } }) } robot := gobot.NewRobot("bot", []gobot.Connection{firmataAdaptor}, []gobot.Device{led_g}, []gobot.Device{led_r}, []gobot.Device{led_b}, []gobot.Device{led_rainbow}, work, ) gbot.AddRobot(robot) gbot.Start() }
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() { gatoradeDashButton, _ := net.ParseMAC("74:75:48:a4:59:a8") gladDashButton, _ := net.ParseMAC("74:75:48:29:a8:7c") flag.Parse() log.Printf("Starting up gobot.io features...") e := edison.NewEdisonAdaptor("edison") // blue led on D4 led1 := gpio.NewLedDriver(e, "led", "4") // red led on D3 led2 := gpio.NewLedDriver(e, "led", "3") e.Connect() led1.Start() led2.Start() log.Printf("Starting up on interface[%v]...", *interfaceName) h, err := pcap.OpenLive(*interfaceName, 65536, true, pcap.BlockForever) if err != nil || h == nil { log.Fatalf("Error opening interface: %s\nPerhaps you need to run as root?\n", err) } defer h.Close() err = h.SetBPFFilter("arp and ((ether src host " + gatoradeDashButton.String() + ") or (ether src host " + gladDashButton.String() + "))") if err != nil { log.Fatalf("Unable to set filter! %s\n", err) } log.Println("Listening for Dash buttons...") packetSource := gopacket.NewPacketSource(h, h.LinkType()) // Since we're using a BPF filter to limit packets to only our buttons, we don't need to worry about anything besides MAC here... for packet := range packetSource.Packets() { ethernetLayer := packet.Layer(layers.LayerTypeEthernet) ethernetPacket, _ := ethernetLayer.(*layers.Ethernet) if bytes.Equal(ethernetPacket.SrcMAC, gatoradeDashButton) { gatoradeButtonPress(led1) } else if bytes.Equal(ethernetPacket.SrcMAC, gladDashButton) { gladButtonPress(led2) } else { log.Printf("Received button press, but don't know how to handle MAC[%v]", ethernetPacket.SrcMAC) } } }
func main() { gbot := gobot.NewGobot() sparkCore := spark.NewSparkCoreAdaptor("spark", "device_id", "access_token") led := gpio.NewLedDriver(sparkCore, "led", "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{sparkCore}, []gobot.Device{led}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() e := edison.NewEdisonAdaptor("edison") button := gpio.NewButtonDriver(e, "myButton", "5") led := gpio.NewLedDriver(e, "myLed", "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, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() pin := "9" brightness := byte(0) fade := byte(5) delay := 30 * time.Millisecond firmataAdaptor := firmata.NewFirmataAdaptor("arduino", "/dev/tty.usbmodem411") led := gpio.NewLedDriver(firmataAdaptor, "led", pin) work := func() { for { led.Brightness(brightness) brightness += fade if brightness == 0 || brightness == 255 { fade = -fade } time.Sleep(delay) } } robot := gobot.NewRobot("bot", []gobot.Connection{firmataAdaptor}, []gobot.Device{led}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() beagleboneAdaptor := beaglebone.NewBeagleboneAdaptor("beaglebone") sensor := gpio.NewAnalogSensorDriver(beagleboneAdaptor, "sensor", "P9_33") led := gpio.NewLedDriver(beagleboneAdaptor, "led", "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, ) gbot.AddRobot(robot) 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() chipAdaptor := chip.NewChipAdaptor("chip") button := gpio.NewButtonDriver(chipAdaptor, "button", "XIO-P6") led := gpio.NewLedDriver(chipAdaptor, "led", "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, ) gbot.AddRobot(robot) gbot.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() e := edison.NewEdisonAdaptor("edison") led := gpio.NewLedDriver(e, "led", "3") 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{e}, []gobot.Device{led}, work, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() firmataAdaptor := firmata.NewFirmataAdaptor("myFirmata", "/dev/ttyACM0") button := gpio.NewButtonDriver(firmataAdaptor, "myButton", "2") led := gpio.NewLedDriver(firmataAdaptor, "myLed", "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, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() r := raspi.NewRaspiAdaptor("raspi") button := gpio.NewButtonDriver(r, "button", "11") led := gpio.NewLedDriver(r, "led", "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, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() e := edison.NewEdisonAdaptor("edison") sensor := gpio.NewAnalogSensorDriver(e, "sensor", "0") led := gpio.NewLedDriver(e, "led", "3") work := func() { sensor.On(gpio.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, ) gbot.AddRobot(robot) gbot.Start() }
func main() { gbot := gobot.NewGobot() firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0") led := gpio.NewLedDriver(firmataAdaptor, "led", "3") 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{firmataAdaptor}, []gobot.Device{led}, work, ) gbot.AddRobot(robot) gbot.Start() }
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() 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() }
// 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() 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() firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0") sensor := gpio.NewAnalogSensorDriver(firmataAdaptor, "sensor", "0") led := gpio.NewLedDriver(firmataAdaptor, "led", "3") work := func() { sensor.On(gpio.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{firmataAdaptor}, []gobot.Device{sensor, led}, 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() 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 main() { app := cli.NewApp() app.Name = "jenpi" app.Usage = "Jenpi CLI" app.Version = version app.Commands = []cli.Command{ { Name: "start", Usage: "start crawling Jenkins", Action: func(c *cli.Context) { urls = c.Args() gbot := gobot.NewGobot() r := raspi.NewRaspiAdaptor("raspi") ledProcessing = gpio.NewLedDriver(r, "led", "7") // BCM 4 ledFail = gpio.NewLedDriver(r, "led", "13") // BCM 17 ledSuccess = gpio.NewLedDriver(r, "led", "11") // BCM 27 gbot.AddRobot(gobot.NewRobot("jenpi", []gobot.Connection{r}, []gobot.Device{ledSuccess, ledProcessing, ledFail}, func() { checkError(ledProcessing.On()) checkError(ledFail.On()) checkError(ledSuccess.On()) fmt.Print("Starting in 1 seconds") time.Sleep(1 * time.Second) gobot.Every(2*time.Second, func() { update() }) }, )) gbot.Start() }, }, } app.Run(os.Args) }
// 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.NewEdisonAdaptor("edison") led := gpio.NewLedDriver(e, "led", "13") e.Connect() led.Start() for { led.Toggle() time.Sleep(1000 * time.Millisecond) } }
func main() { gbot := gobot.NewGobot() api.NewAPI(gbot).Start() digisparkAdaptor := digispark.NewDigisparkAdaptor("Digispark") led := gpio.NewLedDriver(digisparkAdaptor, "led", "0") gbot.Robots = append(gbot.Robots, gobot.NewRobot("digispark", []gobot.Connection{digisparkAdaptor}, []gobot.Device{led}, nil)) gbot.Start() }
func main() { gbot := gobot.NewGobot() api.NewAPI(gbot).Start() firmataAdaptor := firmata.NewFirmataAdaptor("arduino", "/dev/ttyACM0") led11 := gpio.NewLedDriver(firmataAdaptor, "led11", "11") led12 := gpio.NewLedDriver(firmataAdaptor, "led12", "12") led13 := gpio.NewLedDriver(firmataAdaptor, "led13", "13") robot := gobot.NewRobot("minions-bot", []gobot.Connection{firmataAdaptor}, []gobot.Device{led11, led12, led13}, nil, ) gbot.AddRobot(robot) gbot.Start() }