Ejemplo n.º 1
0
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()
}
Ejemplo n.º 2
0
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()
}
Ejemplo n.º 3
0
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()
}
Ejemplo n.º 4
0
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()
			}
		}
	}
}
Ejemplo n.º 5
0
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()
			}
		}
	}
}
Ejemplo n.º 6
0
func main() {
	beagleboneAdaptor := beaglebone.NewAdaptor()
	button := gpio.NewButtonDriver(beagleboneAdaptor, "P8_9")

	work := func() {
		button.On(gpio.ButtonPush, func(data interface{}) {
			fmt.Println("button pressed")
		})

		button.On(gpio.ButtonRelease, func(data interface{}) {
			fmt.Println("button released")
		})
	}

	robot := gobot.NewRobot("buttonBot",
		[]gobot.Connection{beagleboneAdaptor},
		[]gobot.Device{button},
		work,
	)

	robot.Start()
}
Ejemplo n.º 7
0
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()
}
Ejemplo n.º 8
0
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()
}
Ejemplo n.º 9
0
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()
}
Ejemplo n.º 10
0
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()
}
Ejemplo n.º 11
0
func main() {
	master := gobot.NewMaster()
	a := api.NewAPI(master)
	a.Start()

	board := edison.NewAdaptor()
	red := gpio.NewLedDriver(board, "3")
	green := gpio.NewLedDriver(board, "5")
	blue := gpio.NewLedDriver(board, "6")

	button := gpio.NewButtonDriver(board, "7")

	enabled := true
	work := func() {
		red.Brightness(0xff)
		green.Brightness(0x00)
		blue.Brightness(0x00)

		flash := false
		on := true

		gobot.Every(250*time.Millisecond, func() {
			if enabled {
				if flash {
					if on {
						red.Brightness(0x00)
						green.Brightness(0xff)
						blue.Brightness(0x00)
						on = false
					} else {
						red.Brightness(0xff)
						green.Brightness(0x00)
						blue.Brightness(0x00)
						on = true
					}
				}
			}
		})

		button.On(gpio.ButtonPush, func(data interface{}) {
			flash = true
		})

		button.On(gpio.ButtonRelease, func(data interface{}) {
			flash = false
			red.Brightness(0x00)
			green.Brightness(0x00)
			blue.Brightness(0xff)
		})
	}

	robot := gobot.NewRobot(
		"square of fire",
		[]gobot.Connection{board},
		[]gobot.Device{red, green, blue, button},
		work,
	)

	robot.AddCommand("enable", func(params map[string]interface{}) interface{} {
		enabled = !enabled
		return enabled
	})

	master.AddRobot(robot)

	master.Start()
}