|
|
小白一个,折腾了堆代码,运行后返回的数值永远是0,求助{:soso_e136:} {:soso_e136:}
#include <MsTimer2.h>
//volatile int state = HIGH;
int u = 13;//定义U型测速端口
int CW1=8;//连接电机1转向端口到数字接口8
int CW2=9;
int PWM=11; //连接电机1调速端口到数字接口11
int wheel = 0; //记录U型测速模块的次数
wheel++;
//state=!state;
}
float velocity(int n)
{
float vel =n/20;
return vel;
}
void flash()
{
int l;
l=wheel;
vel=velocity(l);
Serial.print(vel);
Serial.print("r/s");
Serial.print("\n");
wheel = 0;
}
void setup ()
{
Serial.begin(9600);
attachInterrupt(0,Count, RISING);
pinMode(CW1,OUTPUT);
pinMode(CW2,OUTPUT);
pinMode(PWM,OUTPUT);
pinMode(u,INPUT);
MsTimer2::set(1000, flash); // 中断设置函数,每 1s 进入一次中断
MsTimer2::start();
}
void loop()
{
digitalWrite(PWM,200);
digitalWrite(CW1,HIGH);//电机1正转
digitalWrite(CW2,LOW);
}
|
本帖子中包含更多资源
您需要 登录 才可以下载或查看,没有帐号?注册
x
|