updated to latest version of keypad library from Github, changes for inverted logic are explicitely marked
This commit is contained in:
parent
71c5ce01d2
commit
87573950e8
3 changed files with 33 additions and 4 deletions
|
@ -15,7 +15,7 @@ byte colPins[COLS] = {8, 7, 6}; //connect to the column pinouts of the keypad
|
||||||
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
|
Keypad kpd = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
|
||||||
|
|
||||||
unsigned long loopCount = 0;
|
unsigned long loopCount = 0;
|
||||||
unsigned long timer_t = 0;
|
unsigned long timer_ms = 0;
|
||||||
|
|
||||||
void setup(){
|
void setup(){
|
||||||
Serial.begin(9600);
|
Serial.begin(9600);
|
||||||
|
@ -33,12 +33,12 @@ void loop(){
|
||||||
// you a relative idea of just how much the debounceTime has changed the
|
// you a relative idea of just how much the debounceTime has changed the
|
||||||
// speed of your code. If you set a high debounceTime your loopCount will
|
// speed of your code. If you set a high debounceTime your loopCount will
|
||||||
// look good but your keypresses will start to feel sluggish.
|
// look good but your keypresses will start to feel sluggish.
|
||||||
if ((millis() - timer_t) > 1000) {
|
if ((millis() - timer_ms) > 1000) {
|
||||||
Serial.print("Your loop code ran ");
|
Serial.print("Your loop code ran ");
|
||||||
Serial.print(loopCount);
|
Serial.print(loopCount);
|
||||||
Serial.println(" times over the last second");
|
Serial.println(" times over the last second");
|
||||||
loopCount = 0;
|
loopCount = 0;
|
||||||
timer_t = millis();
|
timer_ms = millis();
|
||||||
}
|
}
|
||||||
loopCount++;
|
loopCount++;
|
||||||
if(key)
|
if(key)
|
||||||
|
|
|
@ -83,18 +83,31 @@ bool Keypad::getKeys() {
|
||||||
void Keypad::scanKeys() {
|
void Keypad::scanKeys() {
|
||||||
// Re-intialize the row pins. Allows sharing these pins with other hardware.
|
// Re-intialize the row pins. Allows sharing these pins with other hardware.
|
||||||
for (byte r=0; r<sizeKpd.rows; r++) {
|
for (byte r=0; r<sizeKpd.rows; r++) {
|
||||||
|
// Logic needs to be inverted. This way the ESP32’s EXT1 wakeup can be used to detect if the accelerometer pin or any button pin goes high
|
||||||
|
// original from Keypad
|
||||||
|
// pin_mode(rowPins[r],INPUT_PULLUP);
|
||||||
|
// changed for usage in OMOTE
|
||||||
pin_mode(rowPins[r],INPUT);
|
pin_mode(rowPins[r],INPUT);
|
||||||
}
|
}
|
||||||
|
|
||||||
// bitMap stores ALL the keys that are being pressed.
|
// bitMap stores ALL the keys that are being pressed.
|
||||||
for (byte c=0; c<sizeKpd.columns; c++) {
|
for (byte c=0; c<sizeKpd.columns; c++) {
|
||||||
pin_mode(columnPins[c],OUTPUT);
|
pin_mode(columnPins[c],OUTPUT);
|
||||||
|
// original from Keypad
|
||||||
|
// pin_write(columnPins[c], LOW); // Begin column pulse output.
|
||||||
|
// changed for usage in OMOTE
|
||||||
pin_write(columnPins[c], HIGH); // Begin column pulse output.
|
pin_write(columnPins[c], HIGH); // Begin column pulse output.
|
||||||
for (byte r=0; r<sizeKpd.rows; r++) {
|
for (byte r=0; r<sizeKpd.rows; r++) {
|
||||||
|
// original from Keypad
|
||||||
|
// bitWrite(bitMap[r], c, !pin_read(rowPins[r])); // keypress is active low so invert to high.
|
||||||
|
// changed for usage in OMOTE
|
||||||
bitWrite(bitMap[r], c, pin_read(rowPins[r])); // keypress is active low so invert to high.
|
bitWrite(bitMap[r], c, pin_read(rowPins[r])); // keypress is active low so invert to high.
|
||||||
}
|
}
|
||||||
// Set pin to high impedance input. Effectively ends column pulse.
|
// Set pin to high impedance input. Effectively ends column pulse.
|
||||||
pin_write(columnPins[c],LOW);
|
// original from Keypad
|
||||||
|
// pin_write(columnPins[c],HIGH);
|
||||||
|
// changed for usage in OMOTE
|
||||||
|
pin_write(columnPins[c], LOW);
|
||||||
pin_mode(columnPins[c],INPUT);
|
pin_mode(columnPins[c],INPUT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -35,6 +35,22 @@
|
||||||
|
|
||||||
#include "Key.h"
|
#include "Key.h"
|
||||||
|
|
||||||
|
// bperrybap - Thanks for a well reasoned argument and the following macro(s).
|
||||||
|
// See http://arduino.cc/forum/index.php/topic,142041.msg1069480.html#msg1069480
|
||||||
|
#ifndef INPUT_PULLUP
|
||||||
|
#warning "Using pinMode() INPUT_PULLUP AVR emulation"
|
||||||
|
#define INPUT_PULLUP 0x2
|
||||||
|
#define pinMode(_pin, _mode) _mypinMode(_pin, _mode)
|
||||||
|
#define _mypinMode(_pin, _mode) \
|
||||||
|
do { \
|
||||||
|
if(_mode == INPUT_PULLUP) \
|
||||||
|
pinMode(_pin, INPUT); \
|
||||||
|
digitalWrite(_pin, 1); \
|
||||||
|
if(_mode != INPUT_PULLUP) \
|
||||||
|
pinMode(_pin, _mode); \
|
||||||
|
}while(0)
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define OPEN LOW
|
#define OPEN LOW
|
||||||
#define CLOSED HIGH
|
#define CLOSED HIGH
|
||||||
|
|
Loading…
Add table
Reference in a new issue