From 69e6e69c77bad984d2130b378741417d66c7662c Mon Sep 17 00:00:00 2001 From: Jean Jacques Avril Date: Wed, 29 Sep 2021 22:31:05 +0200 Subject: [PATCH] scanAsync improved --- src/Keyboard.cpp | 42 +++++++----------------------------------- 1 file changed, 7 insertions(+), 35 deletions(-) diff --git a/src/Keyboard.cpp b/src/Keyboard.cpp index f8bc932..3b05df6 100644 --- a/src/Keyboard.cpp +++ b/src/Keyboard.cpp @@ -67,41 +67,13 @@ void Keyboard::scanAsync() /** Without delay - scanning only one column per cycle **/ if (millis() < _timeElapsed + this->_debounce) return; - uint8_t key = 0; - switch (_current_scan_col) - { - default: - pcf8574->digitalWrite(7, LOW); - _current_scan_col = 1; - break; - case 1: - { - scanColumn(&key, 1, 4); - pcf8574->digitalWrite(6, LOW); - pcf8574->digitalWrite(7, HIGH); - _current_scan_col = 2; - break; - } - case 2: - { - key=4; - scanColumn(&key, 1, 4); - pcf8574->digitalWrite(5, LOW); - pcf8574->digitalWrite(6, HIGH); - _current_scan_col = 3; - break; - } - case 3: - { - key=8; - scanColumn(&key, 1, 4); - pcf8574->digitalWrite(7, LOW); - pcf8574->digitalWrite(5, HIGH); - _current_scan_col = 1; - break; - } - break; - } + uint8_t key = 4*_current_scan_col; + scanColumn(&key, 1, 4); + pcf8574->digitalWrite(7-(_current_scan_col+1)%3, LOW); + pcf8574->digitalWrite(7-_current_scan_col, HIGH); + _current_scan_col++; + if(_current_scan_col>2) + _current_scan_col = 0; } void Keyboard::scanColumn(uint8_t* key_ptr, uint8_t start, uint8_t stop){