本文整理汇总了Golang中gobot/io/x/gobot.Every函数的典型用法代码示例。如果您正苦于以下问题:Golang Every函数的具体用法?Golang Every怎么用?Golang Every使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了Every函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Golang代码示例。
示例1: main
func main() {
e := joule.NewAdaptor()
led0 := gpio.NewLedDriver(e, "100")
led1 := gpio.NewLedDriver(e, "101")
led2 := gpio.NewLedDriver(e, "102")
led3 := gpio.NewLedDriver(e, "103")
work := func() {
led0.Off()
led1.Off()
led2.Off()
led3.Off()
gobot.Every(1*time.Second, func() {
led0.Toggle()
})
gobot.Every(2*time.Second, func() {
led1.Toggle()
})
gobot.Every(4*time.Second, func() {
led2.Toggle()
})
gobot.Every(8*time.Second, func() {
led3.Toggle()
})
}
robot := gobot.NewRobot("blinkBot",
[]gobot.Connection{e},
[]gobot.Device{led0, led1, led2, led3},
work,
)
robot.Start()
}
示例2: main
func main() {
adaptor := sphero.NewAdaptor("/dev/rfcomm0")
spheroDriver := sphero.NewSpheroDriver(adaptor)
work := func() {
spheroDriver.SetDataStreaming(sphero.DefaultDataStreamingConfig())
spheroDriver.On(sphero.Collision, func(data interface{}) {
fmt.Printf("Collision! %+v\n", data)
})
spheroDriver.On(sphero.SensorData, func(data interface{}) {
fmt.Printf("Streaming Data! %+v\n", data)
})
gobot.Every(3*time.Second, func() {
spheroDriver.Roll(30, uint16(gobot.Rand(360)))
})
gobot.Every(1*time.Second, func() {
r := uint8(gobot.Rand(255))
g := uint8(gobot.Rand(255))
b := uint8(gobot.Rand(255))
spheroDriver.SetRGB(r, g, b)
})
}
robot := gobot.NewRobot("sphero",
[]gobot.Connection{adaptor},
[]gobot.Device{spheroDriver},
work,
)
robot.Start()
}
示例3: main
func main() {
mqttAdaptor := mqtt.NewAdaptor("tcp://test.mosquitto.org:1883", "pinger")
work := func() {
mqttAdaptor.On("hello", func(data []byte) {
fmt.Println("hello")
})
mqttAdaptor.On("hola", func(data []byte) {
fmt.Println("hola")
})
data := []byte("o")
gobot.Every(1*time.Second, func() {
mqttAdaptor.Publish("hello", data)
})
gobot.Every(5*time.Second, func() {
mqttAdaptor.Publish("hola", data)
})
}
robot := gobot.NewRobot("mqttBot",
[]gobot.Connection{mqttAdaptor},
work,
)
robot.Start()
}
示例4: main
func main() {
mqttAdaptor := mqtt.NewAdaptor("tcp://test.mosquitto.org:1883", "blinker")
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
led := gpio.NewLedDriver(firmataAdaptor, "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,
)
robot.Start()
}
示例5: NewSwarmBot
func NewSwarmBot(port string) *gobot.Robot {
spheroAdaptor := sphero.NewAdaptor(port)
spheroDriver := sphero.NewSpheroDriver(spheroAdaptor)
spheroDriver.SetName("Sphero" + port)
work := func() {
spheroDriver.Stop()
spheroDriver.On(sphero.Collision, func(data interface{}) {
fmt.Println("Collision Detected!")
})
gobot.Every(1*time.Second, func() {
spheroDriver.Roll(100, uint16(gobot.Rand(360)))
})
gobot.Every(3*time.Second, func() {
spheroDriver.SetRGB(uint8(gobot.Rand(255)),
uint8(gobot.Rand(255)),
uint8(gobot.Rand(255)),
)
})
}
robot := gobot.NewRobot("sphero",
[]gobot.Connection{spheroAdaptor},
[]gobot.Device{spheroDriver},
work,
)
return robot
}
示例6: main
func main() {
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
led1 := gpio.NewLedDriver(firmataAdaptor, "3")
led2 := gpio.NewLedDriver(firmataAdaptor, "4")
button := gpio.NewButtonDriver(firmataAdaptor, "2")
sensor := gpio.NewAnalogSensorDriver(firmataAdaptor, "0")
work := func() {
gobot.Every(1*time.Second, func() {
led1.Toggle()
})
gobot.Every(2*time.Second, func() {
led2.Toggle()
})
button.On(gpio.ButtonPush, func(data interface{}) {
led2.On()
})
button.On(gpio.ButtonRelease, func(data interface{}) {
led2.Off()
})
sensor.On(gpio.Data, func(data interface{}) {
fmt.Println("sensor", data)
})
}
robot := gobot.NewRobot("bot",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{led1, led2, button, sensor},
work,
)
robot.Start()
}
示例7: main
func main() {
natsAdaptor := nats.NewAdaptorWithAuth("localhost:4222", 1234, "user", "pass")
work := func() {
natsAdaptor.On("hello", func(data []byte) {
fmt.Println("hello")
})
natsAdaptor.On("hola", func(data []byte) {
fmt.Println("hola")
})
data := []byte("o")
gobot.Every(1*time.Second, func() {
natsAdaptor.Publish("hello", data)
})
gobot.Every(5*time.Second, func() {
natsAdaptor.Publish("hola", data)
})
}
robot := gobot.NewRobot("natsBot",
[]gobot.Connection{natsAdaptor},
work,
)
robot.Start()
}
示例8: main
func main() {
master := gobot.NewMaster()
spheros := []string{
"/dev/rfcomm0",
"/dev/rfcomm1",
"/dev/rfcomm2",
}
for _, port := range spheros {
spheroAdaptor := sphero.NewAdaptor(port)
cell := sphero.NewSpheroDriver(spheroAdaptor)
cell.SetName("Sphero" + port)
work := func() {
conway := new(conway)
conway.cell = cell
conway.birth()
cell.On(sphero.Collision, func(data interface{}) {
conway.contact()
})
gobot.Every(3*time.Second, func() {
if conway.alive {
conway.movement()
}
})
gobot.Every(10*time.Second, func() {
if conway.alive {
conway.birthday()
}
})
}
robot := gobot.NewRobot("conway",
[]gobot.Connection{spheroAdaptor},
[]gobot.Device{cell},
work,
)
master.AddRobot(robot)
}
master.Start()
}
示例9: main
func main() {
firmataAdaptor := firmata.NewAdaptor("/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,
)
robot.Start()
}
示例10: main
func main() {
// use "/dev/ttyUSB0" if connecting with USB cable
// use "/dev/ttyAMA0" on devices older than Raspberry Pi 3 Model B
megaPiAdaptor := megapi.NewAdaptor("/dev/ttyS0")
motor := megapi.NewMotorDriver(megaPiAdaptor, 1)
work := func() {
speed := int16(0)
fadeAmount := int16(30)
gobot.Every(100*time.Millisecond, func() {
motor.Speed(speed)
speed = speed + fadeAmount
if speed == 0 || speed == 300 {
fadeAmount = -fadeAmount
}
})
}
robot := gobot.NewRobot("megaPiBot",
[]gobot.Connection{megaPiAdaptor},
[]gobot.Device{motor},
work,
)
robot.Start()
}
示例11: main
func main() {
core := particle.NewAdaptor(os.Args[1], os.Args[2])
led := gpio.NewLedDriver(core, "A1")
work := func() {
brightness := uint8(0)
fadeAmount := uint8(25)
gobot.Every(500*time.Millisecond, func() {
led.Brightness(brightness)
brightness = brightness + fadeAmount
if brightness == 0 || brightness == 255 {
fadeAmount = -fadeAmount
}
})
}
robot := gobot.NewRobot("spark",
[]gobot.Connection{core},
[]gobot.Device{led},
work,
)
robot.Start()
}
示例12: main
func main() {
master := gobot.NewMaster()
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
red := gpio.NewLedDriver(firmataAdaptor, "7")
red.SetName("red")
green := gpio.NewLedDriver(firmataAdaptor, "6")
green.SetName("green")
blue := gpio.NewLedDriver(firmataAdaptor, "5")
blue.SetName("blue")
work := func() {
checkTravis(master.Robot("travis"))
gobot.Every(10*time.Second, func() {
checkTravis(master.Robot("travis"))
})
}
robot := gobot.NewRobot("travis",
[]gobot.Connection{firmataAdaptor},
[]gobot.Device{red, green, blue},
work,
)
master.AddRobot(robot)
master.Start()
}
示例13: main
func main() {
firmataAdaptor := firmata.NewAdaptor("/dev/ttyACM0")
motor := gpio.NewMotorDriver(firmataAdaptor, "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,
)
robot.Start()
}
示例14: main
func main() {
board := edison.NewAdaptor()
board.SetBoard("miniboard")
accel := i2c.NewGroveAccelerometerDriver(board)
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,
)
robot.Start()
}
示例15: main
func main() {
board := edison.NewAdaptor()
screen := i2c.NewGroveLcdDriver(board)
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)
// set a custom character in the first position
screen.SetCustomChar(0, i2c.CustomLCDChars["smiley"])
// add the custom character at the end of the string
screen.Write("goodbye\nhave a nice day " + string(byte(0)))
gobot.Every(500*time.Millisecond, func() {
screen.Scroll(false)
})
})
screen.Home()
time.Sleep(1 * time.Second)
screen.SetRGB(0, 0, 255)
}
robot := gobot.NewRobot("screenBot",
[]gobot.Connection{board},
[]gobot.Device{screen},
work,
)
robot.Start()
}