• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Golang gobot.NewRobot函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了Golang中gobot/io/x/gobot.NewRobot函数的典型用法代码示例。如果您正苦于以下问题:Golang NewRobot函数的具体用法?Golang NewRobot怎么用?Golang NewRobot使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了NewRobot函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Golang代码示例。

示例1: main

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

	api.NewAPI(gbot).Start()

	gbot.AddCommand("echo", func(params map[string]interface{}) interface{} {
		return params["a"]
	})

	loopback := NewLoopbackAdaptor("/dev/null")
	ping := NewPingDriver(loopback, "1")

	work := func() {
		gobot.Every(5*time.Second, func() {
			fmt.Println(ping.Ping())
		})
	}
	r := gobot.NewRobot("TestBot",
		[]gobot.Connection{loopback},
		[]gobot.Device{ping},
		work,
	)

	r.AddCommand("hello", func(params map[string]interface{}) interface{} {
		return fmt.Sprintf("Hello, %v!", params["greeting"])
	})

	gbot.AddRobot(r)
	gbot.Start()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:30,代码来源:batty.go


示例2: main

func main() {
	keys := keyboard.NewDriver()
	mqttAdaptor := mqtt.NewAdaptor("tcp://iot.eclipse.org:1883", "conductor")

	work := func() {
		keys.On(keyboard.Key, func(data interface{}) {
			key := data.(keyboard.KeyEvent)

			switch key.Key {
			case keyboard.ArrowUp:
				mqttAdaptor.Publish("rover/frente", []byte{})
			case keyboard.ArrowRight:
				mqttAdaptor.Publish("rover/derecha", []byte{})
			case keyboard.ArrowDown:
				mqttAdaptor.Publish("rover/atras", []byte{})
			case keyboard.ArrowLeft:
				mqttAdaptor.Publish("rover/izquierda", []byte{})
			}
		})
	}

	robot := gobot.NewRobot("keyboardbot",
		[]gobot.Connection{mqttAdaptor},
		[]gobot.Device{keys},
		work,
	)

	robot.Start()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:29,代码来源:keyboard_mqtt.go


示例3: main

func main() {
	master := gobot.NewMaster()

	a := api.NewAPI(master)
	a.AddHandler(api.BasicAuth("gort", "klatuu"))
	a.Debug()

	a.AddHandler(func(w http.ResponseWriter, r *http.Request) {
		fmt.Fprintf(w, "Hello, %q \n", html.EscapeString(r.URL.Path))
	})
	a.Start()

	master.AddCommand("custom_gobot_command",
		func(params map[string]interface{}) interface{} {
			return "This command is attached to the mcp!"
		})

	hello := master.AddRobot(gobot.NewRobot("hello"))

	hello.AddCommand("hi_there", func(params map[string]interface{}) interface{} {
		return fmt.Sprintf("This command is attached to the robot %v", hello.Name)
	})

	master.Start()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:25,代码来源:hello_api_auth.go


示例4: main

func main() {
	digisparkAdaptor := digispark.NewAdaptor()
	led := gpio.NewLedDriver(digisparkAdaptor, "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,
	)

	robot.Start()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:25,代码来源:digispark_led_brightness.go


示例5: main

func main() {
	r := raspi.NewAdaptor()
	button := gpio.NewButtonDriver(r, "11")
	led := gpio.NewLedDriver(r, "7")

	work := func() {
		button.On(gpio.ButtonPush, func(data interface{}) {
			fmt.Println("button pressed")
			led.On()
		})

		button.On(gpio.ButtonRelease, func(data interface{}) {
			fmt.Println("button released")
			led.Off()
		})
	}

	robot := gobot.NewRobot("buttonBot",
		[]gobot.Connection{r},
		[]gobot.Device{button, led},
		work,
	)

	robot.Start()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:25,代码来源:raspi_button.go


示例6: main

func main() {
	master := gobot.NewMaster()
	api := api.NewAPI(master)
	api.Port = "8080"
	api.Start()

	pebbleAdaptor := pebble.NewAdaptor()
	pebbleDriver := pebble.NewDriver(pebbleAdaptor)

	work := func() {
		pebbleDriver.SendNotification("Hello Pebble!")
		pebbleDriver.On(pebbleDriver.Event("button"), func(data interface{}) {
			fmt.Println("Button pushed: " + data.(string))
		})

		pebbleDriver.On(pebbleDriver.Event("tap"), func(data interface{}) {
			fmt.Println("Tap event detected")
		})
	}

	robot := gobot.NewRobot("pebble",
		[]gobot.Connection{pebbleAdaptor},
		[]gobot.Device{pebbleDriver},
		work,
	)

	master.AddRobot(robot)

	master.Start()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:30,代码来源:pebble.go


示例7: main

func main() {
	master := gobot.NewMaster()
	api.NewAPI(master).Start()

	spheros := map[string]string{
		"Sphero-BPO": "/dev/rfcomm0",
	}

	for name, port := range spheros {
		spheroAdaptor := sphero.NewAdaptor(port)
		spheroDriver := sphero.NewSpheroDriver(spheroAdaptor)

		work := func() {
			spheroDriver.SetRGB(uint8(255), uint8(0), uint8(0))
		}

		robot := gobot.NewRobot(name,
			[]gobot.Connection{spheroAdaptor},
			[]gobot.Device{spheroDriver},
			work,
		)
		robot.AddCommand("turn_blue", func(params map[string]interface{}) interface{} {
			spheroDriver.SetRGB(uint8(0), uint8(0), uint8(255))
			return nil
		})

		master.AddRobot(robot)
	}

	master.Start()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:31,代码来源:sphero_api.go


示例8: 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()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:28,代码来源:firmata_temp36.go


示例9: 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()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:29,代码来源:mqtt_firmata_blink.go


示例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()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:27,代码来源:megapi_motor.go


示例11: main

func main() {
	master := gobot.NewMaster()
	a := api.NewAPI(master)
	a.Port = "8080"
	a.Start()

	pebbleAdaptor := pebble.NewAdaptor()
	pebbleDriver := pebble.NewDriver(pebbleAdaptor)

	work := func() {
		pebbleDriver.On(pebbleDriver.Event("accel"), func(data interface{}) {
			fmt.Println(data.(string))
		})
	}

	robot := gobot.NewRobot("pebble",
		[]gobot.Connection{pebbleAdaptor},
		[]gobot.Device{pebbleDriver},
		work,
	)

	master.AddRobot(robot)

	master.Start()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:25,代码来源:pebble_accelerometer.go


示例12: 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()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:26,代码来源:mqtt_ping.go


示例13: 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()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:25,代码来源:particle_led_brightness.go


示例14: 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()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:26,代码来源:firmata_travis.go


示例15: main

func main() {
	leapAdaptor := leap.NewAdaptor("127.0.0.1:6437")
	spheroAdaptor := sphero.NewAdaptor("/dev/tty.Sphero-YBW-RN-SPP")

	leapDriver := leap.NewDriver(leapAdaptor)
	spheroDriver := sphero.NewSpheroDriver(spheroAdaptor)

	work := func() {
		leapDriver.On(leap.MessageEvent, func(data interface{}) {
			hands := data.(leap.Frame).Hands

			if len(hands) > 0 {
				x := math.Abs(hands[0].Direction[0])
				y := math.Abs(hands[0].Direction[1])
				z := math.Abs(hands[0].Direction[2])
				spheroDriver.SetRGB(scale(x), scale(y), scale(z))
			}
		})
	}

	robot := gobot.NewRobot("leapBot",
		[]gobot.Connection{leapAdaptor, spheroAdaptor},
		[]gobot.Device{leapDriver, spheroDriver},
		work,
	)

	robot.Start()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:28,代码来源:leap_sphero.go


示例16: 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()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:35,代码来源:joule_leds.go


示例17: 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
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:31,代码来源:sphero_multiple.go


示例18: 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()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:35,代码来源:sphero.go


示例19: 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()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:35,代码来源:edison_grove_lcd.go


示例20: 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()
}
开发者ID:hybridgroup,项目名称:gobot,代码行数:26,代码来源:nats.go



注:本文中的gobot/io/x/gobot.NewRobot函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Golang gpio.NewLedDriver函数代码示例发布时间:2022-05-28
下一篇:
Golang gobot.NewEventer函数代码示例发布时间:2022-05-28
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap