Exemplo n.º 1
0
func main() {
	gbot := gobot.NewGobot()

	firmataAdaptor := firmata.NewFirmataAdaptor("myFirmata", "/dev/ttyACM0")
	pin := gpio.NewDirectPinDriver(firmataAdaptor, "pin", "13")

	work := func() {
		level := byte(1)

		gobot.Every(1*time.Second, func() {
			pin.DigitalWrite(level)
			if level == 1 {
				level = 0
			} else {
				level = 1
			}
		})
	}

	robot := gobot.NewRobot("pinBot",
		[]gobot.Connection{firmataAdaptor},
		[]gobot.Device{pin},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemplo n.º 2
0
func main() {
	gbot := gobot.NewGobot()

	firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0")
	blinkm := i2c.NewBlinkMDriver(firmataAdaptor, "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)
			fmt.Println("color", blinkm.Color())
		})
	}

	robot := gobot.NewRobot("blinkmBot",
		[]gobot.Connection{firmataAdaptor},
		[]gobot.Device{blinkm},
		work,
	)

	gbot.AddRobot(robot)
	gbot.Start()
}
Exemplo n.º 3
0
func main() {
	gbot := gobot.NewGobot()

	firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0")
	wiichuck := i2c.NewWiichuckDriver(firmataAdaptor, "wiichuck")

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

		wiichuck.On(wiichuck.Event("c"), func(data interface{}) {
			fmt.Println("c")
		})

		wiichuck.On(wiichuck.Event("z"), func(data interface{}) {
			fmt.Println("z")
		})

		wiichuck.On(wiichuck.Event("error"), func(data interface{}) {
			fmt.Println("Wiichuck error:", data)
		})
	}

	robot := gobot.NewRobot("chuck",
		[]gobot.Connection{firmataAdaptor},
		[]gobot.Device{wiichuck},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemplo n.º 4
0
func main() {
	gbot := gobot.NewGobot()

	firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0")
	motor := gpio.NewMotorDriver(firmataAdaptor, "motor", "3")

	work := func() {
		speed := byte(0)
		fadeAmount := byte(15)

		gobot.Every(100*time.Millisecond, func() {
			motor.Speed(speed)
			speed = speed + fadeAmount
			if speed == 0 || speed == 255 {
				fadeAmount = -fadeAmount
			}
		})
	}

	robot := gobot.NewRobot("motorBot",
		[]gobot.Connection{firmataAdaptor},
		[]gobot.Device{motor},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemplo n.º 5
0
func main() {
	gbot := gobot.NewGobot()

	firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0")

	work := func() {
		gobot.Every(1*time.Second, func() {
			val, err := firmataAdaptor.AnalogRead("0")
			if err != nil {
				fmt.Println(err)
				return
			}

			voltage := (float64(val) * 5) / 1024 // if using 3.3V replace 5 with 3.3
			tempC := (voltage - 0.5) * 100
			tempF := (tempC * 9 / 5) + 32

			fmt.Printf("%.2f°C\n", tempC)
			fmt.Printf("%.2f°F\n", tempF)
		})
	}

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

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemplo n.º 6
0
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()
}
Exemplo n.º 8
0
func main() {
	gbot := gobot.NewGobot()

	firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0")
	servo1 := gpio.NewServoDriver(firmataAdaptor, "servo", "5")
	servo2 := gpio.NewServoDriver(firmataAdaptor, "servo", "3")

	leapAdaptor := leap.NewLeapMotionAdaptor("leap", "127.0.0.1:6437")
	leapDriver := leap.NewLeapMotionDriver(leapAdaptor, "leap")

	work := func() {
		x := 90.0
		z := 90.0
		gobot.On(leapDriver.Events["Message"], func(data interface{}) {
			if len(data.(leap.Frame).Hands) > 0 {
				hand := data.(leap.Frame).Hands[0]
				x = gobot.ToScale(gobot.FromScale(hand.X(), -300, 300), 30, 150)
				z = gobot.ToScale(gobot.FromScale(hand.Z(), -300, 300), 30, 150)
			}
		})
		gobot.Every(10*time.Millisecond, func() {
			servo1.Move(uint8(x))
			servo2.Move(uint8(z))
			fmt.Println("Current Angle: ", servo1.CurrentAngle, ",", servo2.CurrentAngle)
		})
	}

	gbot.Robots = append(gbot.Robots,
		gobot.NewRobot("pwmBot", []gobot.Connection{firmataAdaptor, leapAdaptor}, []gobot.Device{servo1, servo2, leapDriver}, work))
	gbot.Start()
}
Exemplo n.º 9
0
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()
}
Exemplo n.º 10
0
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()
}
Exemplo n.º 11
0
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()
}
Exemplo n.º 12
0
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()
}
Exemplo n.º 13
0
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()
}
Exemplo n.º 14
0
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")

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

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

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

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemplo n.º 15
0
func main() {
	gbot := gobot.NewGobot()

	board := firmata.NewFirmataAdaptor("arduino", "/dev/ttyACM0")
	led := gpio.NewRgbLedDriver(board, "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{board},
		[]gobot.Device{led},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemplo n.º 16
0
func main() {
	gbot := gobot.NewGobot()

	firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0")
	mma7660 := i2c.NewMMA7660Driver(firmataAdaptor, "mma7660")

	work := func() {
		gobot.Every(500*time.Millisecond, func() {
			if x, y, z, err := mma7660.XYZ(); err == nil {
				fmt.Println(x, y, z)
				fmt.Println(mma7660.Acceleration(x, y, z))
			} else {
				fmt.Println(err)
			}
		})
	}

	robot := gobot.NewRobot("mma76602Bot",
		[]gobot.Connection{firmataAdaptor},
		[]gobot.Device{mma7660},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemplo n.º 17
0
func main() {
	gbot := gobot.NewGobot()

	a := api.NewAPI(gbot)
	a.Start()

	board := firmata.NewFirmataAdaptor("arduino", os.Args[1])

	// digital devices
	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 devices
	rotary = gpio.NewGroveRotaryDriver(board, "rotary", "0")
	sensor = gpio.NewGroveTemperatureSensorDriver(board, "sensor", "1")

	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.Every(1*time.Second, func() {
			CheckFireAlarm()
		})
	}

	robot := gobot.NewRobot("airlock",
		[]gobot.Connection{board},
		[]gobot.Device{button, blue, green, red, buzzer, touch, rotary, sensor},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemplo n.º 18
0
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()
}
Exemplo n.º 19
0
func main() {
	gbot := gobot.NewGobot()
	firmataAdaptor := firmata.NewFirmataAdaptor("myFirmata", "/dev/ttyACM0")
	led := gpio.NewLedDriver(firmataAdaptor, "myLed", "13")
	work := func() {
		gobot.Every(1*time.Second, func() {
			led.Toggle()
		})
	}
	gbot.Robots = append(gbot.Robots,
		gobot.NewRobot("blinkBot", []gobot.Connection{firmataAdaptor}, []gobot.Device{led}, work))
	gbot.Start()
}
Exemplo n.º 20
0
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()
}
Exemplo n.º 21
0
func main() {
	gbot := gobot.NewGobot()
	firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0")

	hmc6352 := i2c.NewHMC6352Driver(firmataAdaptor, "hmc6352")

	work := func() {
		gobot.Every(100*time.Millisecond, func() {
			fmt.Println("Heading", hmc6352.Heading)
		})
	}

	gbot.Robots = append(gbot.Robots,
		gobot.NewRobot("hmc6352Bot", []gobot.Connection{firmataAdaptor}, []gobot.Device{hmc6352}, work))
	gbot.Start()
}
Exemplo n.º 22
0
func main() {
	gbot := gobot.NewGobot()

	firmataAdaptor := firmata.NewFirmataAdaptor("arduino", "/dev/ttyACM0")
	buzzer := gpio.NewBuzzerDriver(firmataAdaptor, "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{firmataAdaptor},
		[]gobot.Device{buzzer},
		work,
	)

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemplo n.º 23
0
func main() {
	gbot := gobot.NewGobot()
	firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/ttyACM0")
	servo := gpio.NewServoDriver(firmataAdaptor, "servo", "3")

	work := func() {
		gobot.Every(1*time.Second, func() {
			i := uint8(gobot.Rand(180))
			fmt.Println("Turning", i)
			servo.Move(i)
		})
	}

	gbot.Robots = append(gbot.Robots,
		gobot.NewRobot("servoBot", []gobot.Connection{firmataAdaptor}, []gobot.Device{servo}, work))

	gbot.Start()
}
Exemplo n.º 24
0
// Video: https://www.youtube.com/watch?v=ayNMyUfdAqc
func main() {
	gbot := gobot.NewGobot()

	firmataAdaptor := firmata.NewFirmataAdaptor("firmata", "/dev/tty.usbmodem1451")
	servo1 := gpio.NewServoDriver(firmataAdaptor, "servo", "3")
	servo2 := gpio.NewServoDriver(firmataAdaptor, "servo", "4")
	servo3 := gpio.NewServoDriver(firmataAdaptor, "servo", "5")
	servo4 := gpio.NewServoDriver(firmataAdaptor, "servo", "6")
	servo5 := gpio.NewServoDriver(firmataAdaptor, "servo", "7")

	leapMotionAdaptor := leap.NewLeapMotionAdaptor("leap", "127.0.0.1:6437")
	l := leap.NewLeapMotionDriver(leapMotionAdaptor, "leap")

	work := func() {
		fist := false
		l.On(leap.MessageEvent, func(data interface{}) {
			handIsOpen := len(data.(leap.Frame).Pointables) > 0
			if handIsOpen && fist {
				servo1.Move(0)
				servo2.Move(0)
				servo3.Move(0)
				servo4.Move(0)
				servo5.Move(0)
				fist = false
			} else if !handIsOpen && !fist {
				servo1.Move(120)
				servo2.Move(120)
				servo3.Move(120)
				servo4.Move(120)
				servo5.Move(120)
				fist = true
			}
		})
	}

	robot := gobot.NewRobot("servoBot",
		[]gobot.Connection{firmataAdaptor, leapMotionAdaptor},
		[]gobot.Device{servo1, servo2, servo3, servo4, servo5, l},
		work,
	)

	gbot.AddRobot(robot)
	gbot.Start()
}
Exemplo n.º 25
0
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()
}
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() {
		gobot.Every(100*time.Millisecond, func() {
			val := sensor.Read()
			brightness := uint8(gobot.ToScale(gobot.FromScale(float64(val), 0, 1024), 0, 255))
			fmt.Println("sensor", val)
			fmt.Println("brightness", brightness)
			led.Brightness(brightness)
		})
	}

	gbot.Robots = append(gbot.Robots,
		gobot.NewRobot("sensorBot", []gobot.Connection{firmataAdaptor}, []gobot.Device{sensor, led}, work))

	gbot.Start()
}
Exemplo n.º 27
0
func main() {

	board := firmata.NewFirmataAdaptor("arduino", "/dev/tty.usbmodem411")
	errs := board.Connect()
	if len(errs) != 0 {
		fmt.Println(errs)
		os.Exit(1)
	}
	pin := "9"
	level := byte(0)
	step := byte(5)
	delay := 30 * time.Millisecond
	for {
		board.DigitalWrite(pin, level)
		level += step
		if level == 0 || level == 255 {
			step = -step
		}
		time.Sleep(delay)
	}
}
Exemplo n.º 28
0
func main() {
	gbot := gobot.NewGobot()

	firmataAdaptor := firmata.NewFirmataAdaptor("arduino", "/dev/tty.usbmodem1421")
	sensor := gpio.NewAnalogSensorDriver(firmataAdaptor, "sensor", "0")

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

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

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemplo n.º 29
0
func main() {
	gbot := gobot.NewGobot()

	firmataAdaptor := firmata.NewFirmataAdaptor("arduino", "/dev/ttyACM0")
	led := gpio.NewLedDriver(firmataAdaptor, "led", "13")

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

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

	gbot.AddRobot(robot)

	gbot.Start()
}
Exemplo n.º 30
0
func main() {
	gbot := gobot.NewGobot()

	board := firmata.NewFirmataAdaptor("arduino", os.Args[1])
	blue := gpio.NewLedDriver(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()
}