Sensor-Crash 碰撞传感器常见问题
- Q1:按键串口打印试验中为什么只碰一下串口打印出3个
- A:按键在按下时会产生抖动,串口直接读取按键的值会给出抖动的值。请参考下面按键防抖函数
#include <Microduino_Key.h> Key KeyA(A0, INPUT_PULLUP); Key KeyB(A2, INPUT); void setup(){ Serial.begin(9600); } void loop(){ switch(KeyA.read()){ case SHORT_PRESS: Serial.println("KEY A(digital) SHORT_PRESS"); //短按 break; case LONG_PRESS: Serial.println("KEY A(digital) LONG_PRESS"); //长按 break; } switch(KeyB.read(500, 530)){ case SHORT_PRESS: Serial.println("KEY B(analog) SHORT_PRESS"); //短按 break; case LONG_PRESS: Serial.println("KEY B(analog) LONG_PRESS"); //长按 break; } delay(15); }