树莓派用gobot测试舵机的使用
2024-10-19 12:39:45
package main
import (
"gobot.io/x/gobot"
"gobot.io/x/gobot/drivers/gpio"
"gobot.io/x/gobot/platforms/firmata"
"gobot.io/x/gobot/platforms/leap"
)
// Video: https://www.youtube.com/watch?v=ayNMyUfdAqc
func main() {
firmataAdaptor := firmata.NewAdaptor("/dev/tty.usbmodem1451")
//gpio端口
servo1 := gpio.NewServoDriver(firmataAdaptor, "12")
leapMotionAdaptor := leap.NewAdaptor("127.0.0.1:6437")
l := leap.NewDriver(leapMotionAdaptor)
work := func() {
fist := false
l.On(leap.MessageEvent, func(data interface{}) {
handIsOpen := len(data.(leap.Frame).Pointables) > 0
if handIsOpen && fist {
servo1.Move(0)
fist = false
} else if !handIsOpen && !fist {
servo1.Move(120)
fist = true
}
})
}
robot := gobot.NewRobot("servoBot",
[]gobot.Connection{firmataAdaptor, leapMotionAdaptor},
[]gobot.Device{servo1, l},
work,
)
robot.Start()
}
最新文章
- linux学习第一天,常用命令一
- 【转】Oracle索引失效问题
- JsonPropertyOrder无法为DTO对象进行属性排序
- VirtualBox是什么
- C++ 使用cl命令编辑时发生的问题收录
- 解决android应用程序适用新老android系统版本方法
- oracle存储过程异常捕获
- Android任务栈TaskStack
- postgres 错误duplicate key value violates unique constraint 解决方案
- SpringMVC中的@Controller和@RequestMapping到底什么鬼?
- centos安装svn并创建版本库配置用户分组权限
- 9.3Django
- Python Sleep休眠函数
- ZT 查找字符串中连续最长的数字串
- jgGrid获得的id值是主键的id而不是jqGrid的行号值
- activiti整合spring
- CSS边框长度控制
- CentOS-6.4 minimal - 安装VMware Tools(linux)
- iOS 线程操作库 PromiseKit
- Xshell6连接虚拟机(一)