Esempio n. 1
0
func main() {

	spheroAdaptor := new(gobotSphero.SpheroAdaptor)
	spheroAdaptor.Name = "Sphero"
	spheroAdaptor.Port = "127.0.0.1:4560"

	sphero := gobotSphero.NewSphero(spheroAdaptor)
	sphero.Name = "Sphero"

	connections := []interface{}{
		spheroAdaptor,
	}
	devices := []interface{}{
		sphero,
	}

	work := func() {

		sphero.Stop()

		go func() {
			for {
				gobot.On(sphero.Events["Collision"])
				fmt.Println("Collision Detected!")
			}
		}()

		gobot.Every("2s", func() {
			dir := uint16(gobot.Random(0, 360))
			sphero.Roll(100, dir)
		})

		gobot.Every("3s", func() {
			r := uint8(gobot.Random(0, 255))
			g := uint8(gobot.Random(0, 255))
			b := uint8(gobot.Random(0, 255))
			sphero.SetRGB(r, g, b)
		})
	}

	robot := gobot.Robot{
		Connections: connections,
		Devices:     devices,
		Work:        work,
	}

	robot.Start()
}
Esempio n. 2
0
func main() {

	var robots []gobot.Robot
	spheros := []string{
		"127.0.0.1:4560",
		"127.0.0.1:4561",
		"127.0.0.1:4562",
		"127.0.0.1:4563",
	}

	for s := range spheros {
		spheroAdaptor := new(gobotSphero.SpheroAdaptor)
		spheroAdaptor.Name = "Sphero"
		spheroAdaptor.Port = spheros[s]

		sphero := gobotSphero.NewSphero(spheroAdaptor)
		sphero.Name = "Sphero" + spheros[s]
		sphero.Interval = "0.5s"

		work := func() {
			sphero.Stop()

			go func() {
				for {
					gobot.On(sphero.Events["Collision"])
					fmt.Println("Collision Detected", sphero.Name)
				}
			}()

			gobot.Every("1s", func() {
				sphero.Roll(100, uint16(gobot.Random(0, 360)))
			})
			gobot.Every("3s", func() {
				sphero.SetRGB(uint8(gobot.Random(0, 255)), uint8(gobot.Random(0, 255)), uint8(gobot.Random(0, 255)))
			})
		}

		robots = append(robots, gobot.Robot{Connections: []interface{}{spheroAdaptor}, Devices: []interface{}{sphero}, Work: work})
	}

	gobot.Work(robots)
}
Esempio n. 3
0
func (c *conway) movement() {
	if c.alive == true {
		c.sphero.Roll(100, uint16(gobot.Random(0, 360)))
	}
}