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

	m := mqtt.NewMqttAdaptor("mqtt", "tcp://192.168.0.90:1883", "drone")
	digisparkAdaptor := digispark.NewDigisparkAdaptor("digispark")

	servo := gpio.NewServoDriver(digisparkAdaptor, "servo", "0")

	work := func() {
		servo.Move(10)
		m.On("drop", func(data []byte) {
			servo.Move(150)
			m.Publish("drone", []byte("Dropped"))
		})
	}

	robot := gobot.NewRobot("servoBot",
		[]gobot.Connection{digisparkAdaptor, m},
		[]gobot.Device{servo},
		work,
	)

	gbot.AddRobot(robot)

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

	digisparkAdaptor := digispark.NewDigisparkAdaptor("digispark")
	led := gpio.NewLedDriver(digisparkAdaptor, "led", "0")

	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{digisparkAdaptor},
		[]gobot.Device{led},
		work,
	)

	gbot.AddRobot(robot)

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

	digisparkAdaptor := digispark.NewDigisparkAdaptor("Digispark")
	led := gpio.NewLedDriver(digisparkAdaptor, "led", "0")

	gbot.Robots = append(gbot.Robots,
		gobot.NewRobot("digispark", []gobot.Connection{digisparkAdaptor}, []gobot.Device{led}, nil))
	gbot.Start()
}
Example #4
0
func main() {
	gbot := gobot.NewGobot()
	digisparkAdaptor := digispark.NewDigisparkAdaptor("Digispark")
	led := gpio.NewLedDriver(digisparkAdaptor, "led", "0")

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

	gbot.Robots = append(gbot.Robots,
		gobot.NewRobot("blinkBot", []gobot.Connection{digisparkAdaptor}, []gobot.Device{led}, work))
	gbot.Start()
}
Example #5
0
func main() {
	gbot := gobot.NewGobot()
	digisparkAdaptor := digispark.NewDigisparkAdaptor("digispark")

	servo := gpio.NewServoDriver(digisparkAdaptor, "servo", "0")

	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{digisparkAdaptor}, []gobot.Device{servo}, work))
	gbot.Start()
}