/*内容:以按键单击(表示为0),⻓长击(表示为1) 为输⼊入,统计连续1(包括单个1)出现的状态总共的次 数。
要求 必须包含fsm,中断,不不可以使⽤用轮询!!! 每一次按键,led亮一次 需要进⾏行行消抖*/
int last_state=0;
int current_state=0;
int count=0;
int ledPin=13;
int buttonPin=2;
unsigned long duration;
void setup() {
// put your setup code here, to run once:
Serial.begin(9600);
pinMode( ledPin , OUTPUT);
pinMode( buttonPin , INPUT);
attachInterrupt(0, counter, CHANGE);
}
void loop() {
// put your main code here, to run repeatedly:
switch(current_state){
case 1:
if(last_state==0){
count++;
Serial.print("count:");
Serial.println(count);
}
last_state=current_state;
break;
case 0:
//digitalWrite( ledPin , LOW );
last_state=current_state;
break
嵌入式arduino计数小程序
最新推荐文章于 2023-06-12 22:52:45 发布