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() { 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() { r := raspi.NewAdaptor() adaFruit := i2c.NewAdafruitMotorHatDriver(r) work := func() { gobot.Every(5*time.Second, func() { adafruitServoMotorRunner(adaFruit) }) } robot := gobot.NewRobot("adaFruitBot", []gobot.Connection{r}, []gobot.Device{adaFruit}, work, ) robot.Start() }
func main() { r := raspi.NewAdaptor() blinkm := i2c.NewBlinkMDriver(r) 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{r}, []gobot.Device{blinkm}, work, ) robot.Start() }
func main() { r := raspi.NewAdaptor() sht3x := i2c.NewSHT3xDriver(r) work := func() { sht3x.Units = "F" sht3x.Start() sn, err := sht3x.SerialNumber() fmt.Printf("Serial Number: 0x%08x, err: %v\n", sn, err) gobot.Every(5*time.Second, func() { temp, rh, err := sht3x.Sample() fmt.Printf("Temp: %f F, Relative Humidity: %f, err: %v\n", temp, rh, err) }) } robot := gobot.NewRobot("SHT3xbot", []gobot.Connection{r}, []gobot.Device{sht3x}, work, ) robot.Start() }