|
楼主 |
发表于 2019-11-19 08:47:43
|
显示全部楼层
是的,我设定的是200MS为区分,小于为短按,大于为长按
- #define IRRevPin 36
- uint32_t data_ready = 0;
- bool ir_sts = false;
- int deb = 0;
- int hold_count = 0;
- int code_count = 0;
- uint32_t code_value = 0;
- char code_char = ' ';
- char words[11] = " ";
- void loop() {
- bool new_sts = false;
- delay(5);
- if(digitalRead(IRRevPin))
- {
- matrix.fillCircle(15,35,5,LED_BLUE_LOW);
- new_sts = true;
- }
- else
- {
- matrix.fillCircle(15,35,5,LED_BLACK);
- }
- if(ir_sts)
- {
- if(!new_sts)
- {
- deb++;
- if(deb > 5)
- {
- deb = 0;
- ir_sts = false;
- //下降沿来测算高脉冲宽度,宽度长则为1,短则为0
- uint32_t is_long = 0;
- if(hold_count > 40)
- {
- matrix.fillCircle(32,35,5,LED_BLUE_LOW);
- is_long = 1;
- }
- else
- {
- matrix.fillCircle(32,35,5,LED_BLACK);
- }
- code_value = (code_value<<1)| is_long;
- //5个code_count记为一个周期。
- code_count++;
- // if(code_count >=5)
- if(code_count >=8)
- {
- code_char = ' ';
- code_count = 0;
- #if 0
- switch(code_value)
- {
- case 0x0f: code_char='1'; break;
- case 0x07: code_char='2'; break;
- case 0x03: code_char='3'; break;
- case 0x01: code_char='4'; break;
- case 0x00: code_char='5'; break;
- case 0x10: code_char='6'; break;
- case 0x18: code_char='7'; break;
- case 0x1c: code_char='8'; break;
- case 0x1e: code_char='9'; break;
- case 0x1f: code_char='0'; break;
- case 0x11: code_char='='; break;
- case 0x12: code_char='/'; break;
- case 0x13: code_char='*'; break;
- case 0x14: code_char='+'; break;
- case 0x15: code_char='-'; break;
- }
- #else
- code_char = code_value;
- #endif
- //存储最新字符,并显示在屏幕
- for(int x=0; x<9; x++)
- {
- words[x] = words[x+1];
- }
- words[9] = code_char;
- for(int x=0; x<10; x++){
- matrix.drawChar(2+6*x,52,words[x],LED_RED_MEDIUM, LED_BLACK, 1);
- }
- code_value = 0;
- }
- matrix.drawChar(47,35,'0'+code_count,LED_RED_MEDIUM,0,1);
- }
- }
- else
- {
- deb = 0;
- }
- hold_count++;
- }
- else
- {
- if(new_sts)
- {
- deb++;
- if(deb > 5)
- {
- deb = 0;
- ir_sts = true;
- }
- }
- hold_count = 0;
- }
- }
复制代码 |
|