Beispiel #1
0
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()
}
Beispiel #2
0
/*
This function is used if only the rotary port is in play.
func mapValueToColor(i int) (int, int, int) {
	// Masking to account for very sensitive rotary
	red := ((i & (1 << 1)) << 2) | ((i & (1 << 4)) << 0) | ((i & (1 << 7)) >> 2)
	green := ((i & (1 << 2)) << 1) | ((i & (1 << 5)) >> 1) | ((i & (1 << 8)) >> 3)
	blue := ((i & (1 << 3)) << 0) | ((i & (1 << 6)) >> 2) | ((i & (1 << 9)) >> 4)

	return red, green, blue
}
*/
func main() {
	gbot := gobot.NewGobot()

	board := edison.NewEdisonAdaptor("edison")
	screen := i2c.NewGroveLcdDriver(board, "screen")
	sensorRotary := gpio.NewGroveRotaryDriver(board, "sensor", "0")
	sensorLight := gpio.NewGroveLightSensorDriver(board, "light", "1")
	sensorTemp := gpio.NewGroveTemperatureSensorDriver(board, "temp", "2")

	work := func() {
		var r, g, b int

		gobot.On(sensorRotary.Event("data"), func(data interface{}) {
			r = data.(int) >> 2
		})

		gobot.On(sensorLight.Event("data"), func(data interface{}) {
			fmt.Printf("%d\n", data)
			g = data.(int) * 255 / 790
		})

		gobot.Every(time.Millisecond*500, func() {
			b = int(gobot.ToScale(gobot.FromScale(sensorTemp.Temperature(), 25, 35), 0, 255))
			screen.Clear()
			screen.Home()
			screen.SetRGB(r, g, b)
			screen.Write(fmt.Sprintf("#%02X%02X%02X", r, g, b))
		})

	}

	robot := gobot.NewRobot("screenBot",
		[]gobot.Connection{board},
		[]gobot.Device{screen, sensorRotary, sensorLight, sensorTemp},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
func main() {
	gbot := gobot.NewGobot()

	board := edison.NewEdisonAdaptor("board")
	sensor := gpio.NewGroveRotaryDriver(board, "sensor", "0")

	work := func() {
		gobot.On(sensor.Event("data"), func(data interface{}) {
			fmt.Println("sensor", data)
		})
	}

	robot := gobot.NewRobot("sensorBot",
		[]gobot.Connection{board},
		[]gobot.Device{sensor},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}