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

	board := edison.NewEdisonAdaptor("edison")
	button = gpio.NewGroveButtonDriver(board, "button", "2")
	blue = gpio.NewGroveLedDriver(board, "blue", "3")
	green = gpio.NewGroveLedDriver(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()
}
func main() {
	gbot := gobot.NewGobot()

	e := edison.NewEdisonAdaptor("edison")
	button := gpio.NewGroveButtonDriver(e, "button", "2")

	work := func() {
		gobot.On(button.Event(gpio.Push), func(data interface{}) {
			fmt.Println("On!")
		})

		gobot.On(button.Event(gpio.Release), func(data interface{}) {
			fmt.Println("Off!")
		})

	}

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

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemple #3
0
func main() {
	gbot := gobot.NewGobot()

	edisonAdaptor := edison.NewEdisonAdaptor("edison")
	blinkm := i2c.NewBlinkMDriver(edisonAdaptor, "blinkm")
	sensor := gpio.NewAnalogSensorDriver(edisonAdaptor, "sensor", "2")

	work := func() {
		gobot.On(sensor.Event("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)
			blinkm.Rgb(0, brightness, 0)
		})
	}

	robot := gobot.NewRobot("sensorBot",
		[]gobot.Connection{edisonAdaptor},
		[]gobot.Device{blinkm, sensor},
		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()
}
Exemple #5
0
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()

	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()
}
Exemple #7
0
func main() {
	flag.Parse()
	config, err := config.Configuration(*configFilePath)
	if err != nil {
		panic(err)
	}
	logging.SetLogLevel(config.LogLevel)
	gbot := gobot.NewGobot()

	broker := broker.NewMQTTBroker("edison processor", config.BrokerUrl)
	err = broker.Connect()
	if err != nil {
		panic(err)
	}
	logging.Log.Info("Successfully connected to broker")

	adapter := edison.NewEdisonAdaptor("edison")
	//	adapter := testutils.NewMockAdapter("mockAdapter")
	service := sensors.Initialize(gbot, adapter, broker)

	for pin, stype := range config.Sensors {
		switch stype {
		case "touch":
			service.NewTouchSensor(pin)
		case "sound":
			service.NewSoundSensor(pin)
		}
	}

	logging.Log.Info("Starting gobot bot...")
	gbot.Start()
}
func main() {
	gbot := gobot.NewGobot()

	e := edison.NewEdisonAdaptor("edison")
	touch := gpio.NewGroveTouchDriver(e, "touch", "2")

	work := func() {
		gobot.On(touch.Event(gpio.Push), func(data interface{}) {
			fmt.Println("On!")
		})

		gobot.On(touch.Event(gpio.Release), func(data interface{}) {
			fmt.Println("Off!")
		})

	}

	robot := gobot.NewRobot("blinkBot",
		[]gobot.Connection{e},
		[]gobot.Device{touch},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemple #9
0
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()
}
Exemple #10
0
func main() {
	gbot := gobot.NewGobot()

	e := edison.NewEdisonAdaptor("edison")
	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()
}
Exemple #11
0
func main() {
	gbot := gobot.NewGobot()

	board := edison.NewEdisonAdaptor("edison")
	screen := i2c.NewGroveLcdDriver(board, "screen")

	work := func() {
		screen.Write("hello")

		screen.SetRGB(255, 0, 0)

		gobot.After(5*time.Second, func() {
			screen.Clear()
			screen.Home()
			screen.SetRGB(0, 255, 0)
			screen.Write("goodbye")
		})

		screen.Home()
		<-time.After(1 * time.Second)
		screen.SetRGB(0, 0, 255)
	}

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

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemple #12
0
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 := 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()
}
Exemple #14
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()
}
Exemple #15
0
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()
}
Exemple #16
0
func main() {
	gbot := gobot.NewGobot()

	e := edison.NewEdisonAdaptor("edison")
	m := mqtt.NewMqttAdaptor("mqtt", "tcp://192.168.0.90:1883", "pump")

	lever := gpio.NewButtonDriver(e, "lever", "2")
	fault := gpio.NewButtonDriver(e, "fault", "4")
	pump := gpio.NewDirectPinDriver(e, "pump", "13")

	work := func() {
		dgram := url.Values{
			"name":         {"Four"},
			"dispenser_id": {"4"},
			"drink_id":     {"0"},
			"event":        {"online"},
			"details":      {"dispenser"},
		}
		pumping := false
		served := byte(0)

		m.On("startPump", func(data []byte) {
			if !pumping {
				pumping = true
				pump.DigitalWrite(1)
				served++
				dgram.Set("event", "online")
				dgram.Set("drink_id", fmt.Sprintf("%v", served))
				m.Publish("pumped", []byte(dgram.Encode()))
				gobot.After(2*time.Second, func() {
					pump.DigitalWrite(0)
					pumping = false
				})
			}
		})

		gobot.On(lever.Event("push"), func(data interface{}) {
			m.Publish("pump", []byte{})
		})

		m.On("startFault", func(data []byte) {
			dgram.Set("event", "error")
			m.Publish("fault", []byte(dgram.Encode()))
		})

		gobot.On(fault.Event("push"), func(data interface{}) {
			m.Publish("startFault", []byte{})
		})
	}

	gbot.AddRobot(gobot.NewRobot("brewmachine",
		[]gobot.Connection{e, m},
		[]gobot.Device{lever, fault, pump},
		work,
	))

	gbot.Start()
}
Exemple #17
0
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() {
	flag.Parse()

	// Initialize Intel Edison
	edisonAdaptor := edison.NewEdisonAdaptor("edison")
	edisonAdaptor.Connect()

	lightSensor := gpio.NewGroveLightSensorDriver(edisonAdaptor, "light", *sensorLightPin, *sensorPollingInterval)
	lightSensor.Start()
	gobot.On(lightSensor.Event("data"), func(data interface{}) {
		raw := float64(data.(int))
		// convert to lux
		resistance := (1023.0 - raw) * 10.0 / raw * 15.0
		light = 10000.0 / math.Pow(resistance, 4.0/3.0)
		lightUpdated = time.Now()
		log.Debugln("illuminance: ", light)
	})

	soundSensor := gpio.NewGroveSoundSensorDriver(edisonAdaptor, "sound", *sensorSoundPin, *sensorPollingInterval)
	soundSensor.Start()
	gobot.On(soundSensor.Event("data"), func(data interface{}) {
		sound = float64(data.(int))
		soundUpdated = time.Now()
		log.Debugln("sound level: ", sound)
	})

	tempSensor := gpio.NewGroveTemperatureSensorDriver(edisonAdaptor, "temp", *sensorTempPin, *sensorPollingInterval)
	tempSensor.Start()
	gobot.On(tempSensor.Event("data"), func(data interface{}) {
		celsius = data.(float64)
		fahrenheit = celsius*1.8 + 32
		tempUpdated = time.Now()
		log.Debugln("temperature: ", celsius)
	})

	// Initialize prometheus exporter
	exporter := NewExporter()
	prometheus.MustRegister(exporter)

	log.Infof("Listening on: %s", *listenAddress)
	http.Handle(*metricPath, prometheus.Handler())
	http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
		w.Write([]byte(`
			<html>
			<head>
				<title>IoT Edison exporter</title>
			</head>
			<body>
				<h1>Prometheus exporter for sensor metrics from Intel Edison</h1>
				<p><a href='` + *metricPath + `'>Metrics</a></p>
			</body>
			</html>
		`))
	})
	log.Fatal(http.ListenAndServe(*listenAddress, nil))
}
// 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)
	}
}
Exemple #20
0
func main() {

	flag.Parse()

	gbot := gobot.NewGobot()

	e := edison.NewEdisonAdaptor("edison")

	pwmA := gpio.NewDirectPinDriver(e, "pwmA", "3")
	breakA := gpio.NewDirectPinDriver(e, "breakA", "9")
	dirA := gpio.NewDirectPinDriver(e, "dirA", "12")

	pwmB := gpio.NewDirectPinDriver(e, "pwmB", "5")
	breakB := gpio.NewDirectPinDriver(e, "breakB", "8")
	dirB := gpio.NewDirectPinDriver(e, "dirB", "13")

	work := func() {
		tank := tank.NewTank(pwmA, breakA, dirA, pwmB, breakB, dirB, *maxspeed, *maxrotate)

		go func() {

			wb := webbot.New(*host, *video, *pass, tank)

			for {
				if err := wb.Run(); err != nil {
					log.Printf("RUN ERROR: %v\n", err.Error())
				}
				time.Sleep(1 * time.Second)
			}

		}()

	}

	robot := gobot.NewRobot("dartBot",
		[]gobot.Connection{e},
		[]gobot.Device{pwmA},
		[]gobot.Device{breakA},
		[]gobot.Device{dirA},
		[]gobot.Device{pwmB},
		[]gobot.Device{dirB},
		[]gobot.Device{breakB},
		work,
	)

	gbot.AddRobot(robot)
	gbot.Start()

}
Exemple #21
0
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()

	board := edison.NewEdisonAdaptor("edison")
	buzzer := gpio.NewBuzzerDriver(board, "buzzer", "3")

	work := func() {
		type note struct {
			tone     float64
			duration float64
		}

		song := []note{
			{gpio.C4, gpio.Quarter},
			{gpio.C4, gpio.Quarter},
			{gpio.G4, gpio.Quarter},
			{gpio.G4, gpio.Quarter},
			{gpio.A4, gpio.Quarter},
			{gpio.A4, gpio.Quarter},
			{gpio.G4, gpio.Half},
			{gpio.F4, gpio.Quarter},
			{gpio.F4, gpio.Quarter},
			{gpio.E4, gpio.Quarter},
			{gpio.E4, gpio.Quarter},
			{gpio.D4, gpio.Quarter},
			{gpio.D4, gpio.Quarter},
			{gpio.C4, gpio.Half},
		}

		for _, val := range song {
			buzzer.Tone(val.tone, val.duration)
			<-time.After(10 * time.Millisecond)
		}
	}

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

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemple #23
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.NewGroveSoundSensorDriver(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()
}
func main() {
	gbot := gobot.NewGobot()

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

	work := func() {
		gobot.Every(500*time.Millisecond, func() {
			fmt.Println("current temp (c): ", sensor.Temperature())
		})
	}

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

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemple #26
0
func main() {
	gbot := gobot.NewGobot()

	e := edison.NewEdisonAdaptor("edison")
	led := gpio.NewGroveLedDriver(e, "led", "4")

	work := func() {
		gobot.Every(1*time.Second, func() {
			led.Toggle()
		})
	}

	robot := gobot.NewRobot("blinkBot",
		[]gobot.Connection{e},
		[]gobot.Device{led},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemple #27
0
func main() {
	gbot := gobot.NewGobot()

	board := edison.NewEdisonAdaptor("edison")
	blue := gpio.NewGroveLedDriver(board, "blue", "3")

	work := func() {
		gobot.Every(1*time.Second, func() {
			blue.Toggle()
		})
	}

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

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemple #28
0
func main() {
	gbot := gobot.NewGobot()

	board := edison.NewEdisonAdaptor("edison")
	lidar := NewLIDARLiteDriver(board, "lidar")
	screen := i2c.NewGroveLcdDriver(board, "screen")

	work := func() {
		gobot.Every(500*time.Millisecond, func() {
			distance, err := lidar.Distance()
			if err != nil {
				fmt.Println("error: ", err)
			}
			dist := float32(distance) / 2.54
			fmt.Println("Distance (in)", dist)
			screen.Clear()
			screen.Home()
			screen.Write(fmt.Sprintf("%f\"", dist))
		})
	}

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

	gbot.AddRobot(robot)

	/*
		if errs := screen.Start(); len(errs) > 0 {
			for _, err := range errs {
				fmt.Println(err)
			}
		}
	*/

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

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

	work := func() {
		sensor.On(gpio.Vibration, func(data interface{}) {
			fmt.Println("got one!")
		})
	}

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

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemple #30
0
func main() {
	e := edison.NewEdisonAdaptor("edison")
	led := gpio.NewLedDriver(e, "led", "13")
	button := gpio.NewButtonDriver(e, "button", "5")

	e.Connect()
	led.Start()
	button.Start()

	led.Off()

	buttonEvents := button.Subscribe()
	for {
		select {
		case event := <-buttonEvents:
			fmt.Println("Event:", event.Name, event.Data)
			if event.Name == gpio.ButtonPush {
				led.Toggle()
			}
		}
	}
}