您的位置 首页 UI设计教程

arduino系统教程


关于arduino系统教程最佳答案


arduino系统教程


1.就是找到驱动安装就好,驱动就在程序包里面driver目录中


关于arduino系统教程相关答案


2.舵机和超声波调试代码#include #include metro measuredistance = metro(50); metro sweepservo = metro(20); unsigned long actualdistance = 0; servo myservo; 创建舵机 int pos = 60; int sweepflag = 1; int urpwm = 3; pwm输出0-25000us,每50us代表1cm int urtrig= 10; pwm trigger pin pwm串口为10 uint8_t enpwmcmd[4]={0x44,0x02,0xbb,0x01}; distance measure command 距离测量命令 void setup(){ serial initialization 串行初始化 myservo.attach(9); 舵机串口为9 serial.begin(9600); sets the baud rate to 9600 sensorsetup(); } void loop(){ if(measuredistance.check() == 1){ actualdistance = measuredistance(); serial.println(actualdistance); delay(100); } if(sweepservo.check() == 1){ servosweep(); } } void sensorsetup(){ pinmode(urtrig,output); a low pull on pin comptrig digitalwrite(urtrig,high); set to high pinmode(urpwm, input); sending enable pwm mode command 发送使能控制模式命令 for(int i=0;i serial.write(enpwmcmd[i]); } } int measuredistance(){ a low pull on pin comptrig triggering a sensor reading 触发传感器读数 digitalwrite(urtrig, low); digitalwrite(urtrig, high); reading pin pwm will output pulses 读引脚脉宽调制将输出脉冲 unsigned long distance=pulsein(urpwm,low); if(distance==50000){ the reading is invalid.阅读无效 serial.print("invalid"); }else{ distance=distance50; every 50us low level stands for 1cm } return distance; } void servosweep(){ if(sweepflag ){ if(pos>=60 pos pos=pos+1; in steps of 1 degree 1度角度的转动 myservo.write(pos); tell servo to go to position in variable 'pos' 告诉舵机转动的角度 } if(pos>119) sweepflag = false; assign the variable again 重新分配变量 }else { if(pos>=60 pos pos=pos-1; myservo.write(pos); } if(pos } } 需要加载一个metro.h的库,这只是调试机器,余下的完全看你的发挥了,加上电机


了解更多arduino系统教程类似问题


realguitar5安装教程
ui设计教程之学习方法
ui自学教程入门视频教程

发表评论

您的电子邮箱地址不会被公开。 必填项已用*标注