diff --git a/examples/keybrd_shift_register/keybrd_shift_register.ino b/examples/keybrd_shift_register/keybrd_shift_register.ino index b331696..62e7ea3 100644 --- a/examples/keybrd_shift_register/keybrd_shift_register.ino +++ b/examples/keybrd_shift_register/keybrd_shift_register.ino @@ -30,7 +30,11 @@ Layout // =============== CONFIGURATION =============== ScanDelay scanDelay(9000); -const bool RowScanner_PinsArray::ACTIVE_HIGH = 0; //left matrix is active low + +//active state of left matrix +const bool RowScanner_PinsArray::STROBE_ON = LOW; +const bool RowScanner_PinsArray::STROBE_OFF = HIGH; + const uint8_t RowScanner_SPIShiftRegisters::SHIFT_LOAD = 10; Debug debug; diff --git a/src/RowScanner_PinsArray.cpp b/src/RowScanner_PinsArray.cpp index 19742bf..5c4bc61 100644 --- a/src/RowScanner_PinsArray.cpp +++ b/src/RowScanner_PinsArray.cpp @@ -11,13 +11,13 @@ RowScanner_PinsArray::RowScanner_PinsArray(const uint8_t STROBE_PIN, //configure row pinMode(STROBE_PIN, OUTPUT); - if (ACTIVE_HIGH) + if (STROBE_ON == LOW) //if active low { - mode = INPUT; //requires external pull-down resistor + mode = INPUT_PULLUP; //uses internal pull-up resistor } else { - mode = INPUT_PULLUP; //uses internal pull-up resistor + mode = INPUT; //requires external pull-down resistor } //configure cols @@ -41,36 +41,20 @@ read_pins_t RowScanner_PinsArray::scan(uint8_t& keyCount) read_pins_t rowState = 0; //bitwise, one col per bit, 1 means key is pressed read_pins_t rowMask = 1; //bitwise, one col per bit, active col bit is 1 - //strobe row on - if (ACTIVE_HIGH) - { - digitalWrite(STROBE_PIN, HIGH); - } - else //activeLow - { - digitalWrite(STROBE_PIN, LOW); - } + digitalWrite(STROBE_PIN, STROBE_ON); delayMicroseconds(3); //time to stablize voltage //read all the column pins for (uint8_t i=0; i < READ_PIN_COUNT; i++) { - if ( digitalRead(READ_PINS[i]) == ACTIVE_HIGH ) + if ( digitalRead(READ_PINS[i]) == STROBE_ON ) { rowState |= rowMask; } rowMask <<= 1; } - //strobe row off - if (ACTIVE_HIGH) - { - digitalWrite(STROBE_PIN, LOW); - } - else //activeLow - { - digitalWrite(STROBE_PIN, HIGH); - } + digitalWrite(STROBE_PIN, STROBE_OFF); keyCount = READ_PIN_COUNT; return rowState; diff --git a/src/RowScanner_PinsArray.h b/src/RowScanner_PinsArray.h index 09f5a75..f8fd78b 100644 --- a/src/RowScanner_PinsArray.h +++ b/src/RowScanner_PinsArray.h @@ -12,7 +12,8 @@ Constructor is in RowScanner_PinsArray.cpp class RowScanner_PinsArray { private: - static const bool ACTIVE_HIGH; //logic level of strobe pin: 0=activeLow, 1=activeHigh + static const bool STROBE_ON; //logic level of strobe on, HIGH or LOW + static const bool STROBE_OFF; //logic level of strobe off, HIGH or LOW const uint8_t STROBE_PIN; //Arduino pin number connected to this row const uint8_t* const READ_PINS; //array of read pin numbers const uint8_t READ_PIN_COUNT; //number of read pins diff --git a/src/RowScanner_PinsBitwise.cpp b/src/RowScanner_PinsBitwise.cpp index b00a052..405dc76 100644 --- a/src/RowScanner_PinsBitwise.cpp +++ b/src/RowScanner_PinsBitwise.cpp @@ -5,13 +5,13 @@ Strobes the row and reads the columns. ColPort* const RowScanner_PinsBitwise::scan() { //strobe row on - if (activeHigh) + if (STROBE_ON == LOW) { - refRowPort.setActivePinHigh(strobePin); + refRowPort.setActivePinLow(strobePin); } else //activeLow { - refRowPort.setActivePinLow(strobePin); + refRowPort.setActivePinHigh(strobePin); } delayMicroseconds(3); //time to stablize voltage @@ -19,13 +19,13 @@ ColPort* const RowScanner_PinsBitwise::scan() refColPort.read(); //strobe row off - if (activeHigh) + if (STROBE_ON == LOW) { - refRowPort.setActivePinLow(strobePin); + refRowPort.setActivePinHigh(strobePin); } else //activeLow { - refRowPort.setActivePinHigh(strobePin); + refRowPort.setActivePinLow(strobePin); } return &refColPort; diff --git a/src/RowScanner_PinsBitwise.h b/src/RowScanner_PinsBitwise.h index 23ae99f..9a9c642 100644 --- a/src/RowScanner_PinsBitwise.h +++ b/src/RowScanner_PinsBitwise.h @@ -19,7 +19,7 @@ class RowScanner_PinsBitwise ColPort& refColPort) : refRowPort(refRowPort), strobePin(strobePin), refColPort(refColPort) {} - static const bool activeHigh; //logic level of strobe pin: 0=activeLow, 1=activeHigh + static const bool STROBE_ON; //logic level of strobe on, active state, HIGH or LOW virtual ColPort* const scan(); }; #endif diff --git a/src/Row_uC.h b/src/Row_uC.h index 2bc969b..580de84 100644 --- a/src/Row_uC.h +++ b/src/Row_uC.h @@ -10,11 +10,11 @@ Instantiation ------------- Definition of DELAY_MICROSECONDS is explained in RowBase.cpp. -todo Definition of activeHigh is explained in RowScanner_Interface.h Example instantiation of a row: const unsigned int RowBase::DELAY_MICROSECONDS = 1000; - const bool RowScanner_PinsArray::activeHigh = 0; + const bool RowScanner_PinsArray::STROBE_ON = LOW; //logic level of strobe on + const bool RowScanner_PinsArray::STROBE_OFF = HIGH; //logic level of strobe off const uint8_t colPins[] = {0,1,2,3,7,8}; const uint8_t COL_PIN_COUNT = sizeof(colPins)/sizeof(*colPins); diff --git a/src/config_keybrd.h b/src/config_keybrd.h index 30f2c8f..5e3e1c3 100644 --- a/src/config_keybrd.h +++ b/src/config_keybrd.h @@ -8,7 +8,7 @@ If your 8-bit AVR is running low on memory, using a smaller type saves SRAM. Using smaller types on a 32-bit uC (Teensy LC) would accomplish nothing. */ -/* Uncomment a typedef read_pins_t that covers all col pins of the RowScanner object with the most col pins i.e. +/* Uncomment a typedef read_pins_t size that covers all col pins of all RowScanner objects i.e. For RowScanner_PinsArray, RowScanner_PinsArray::READ_PIN_COUNT For RowScanner_SPIShiftRegisters, RowScanner_SPIShiftRegisters::KEY_COUNT For RowScanner_PinsBitwise, cover the last 1 bit in RowScanner_PinsBitwise::strobePin