{ | { | ||||
//these variables are all bitwise, one bit per key | //these variables are all bitwise, one bit per key | ||||
read_pins_t rowState; //1 means pressed, 0 means released | read_pins_t rowState; //1 means pressed, 0 means released | ||||
uint8_t readPinCount; | |||||
//uint8_t readPinCount; | |||||
read_pins_t debouncedChanged; //1 means debounced changed | read_pins_t debouncedChanged; //1 means debounced changed | ||||
rowState = scanner.scan(readPinCount); | |||||
rowState = scanner.scan(); | |||||
debouncedChanged = debouncer.debounce(rowState, debounced); | debouncedChanged = debouncer.debounce(rowState, debounced); | ||||
pressRelease(readPinCount, debouncedChanged); | |||||
pressRelease(READ_PIN_COUNT, debouncedChanged); | |||||
} | } | ||||
void Row_ShiftRegisters::begin() | void Row_ShiftRegisters::begin() |
Scanner_ShiftRegs74HC165 scanner; | Scanner_ShiftRegs74HC165 scanner; | ||||
Debouncer_4Samples debouncer; | Debouncer_4Samples debouncer; | ||||
//Debouncer_Not debouncer; //passed test | //Debouncer_Not debouncer; //passed test | ||||
const uint8_t READ_PIN_COUNT; //number of read pins | |||||
public: | public: | ||||
Row_ShiftRegisters(const uint8_t STROBE_PIN, uint8_t READ_PIN_COUNT, Key *const ptrsKeys[]) | Row_ShiftRegisters(const uint8_t STROBE_PIN, uint8_t READ_PIN_COUNT, Key *const ptrsKeys[]) | ||||
: Row(ptrsKeys), scanner(STROBE_PIN, READ_PIN_COUNT) { } | |||||
: Row(ptrsKeys), scanner(STROBE_PIN, READ_PIN_COUNT), READ_PIN_COUNT(READ_PIN_COUNT) { } | |||||
void begin(); | void begin(); | ||||
void process(); | void process(); | ||||
}; | }; |
{ | { | ||||
//these variables are all bitwise, one bit per key | //these variables are all bitwise, one bit per key | ||||
read_pins_t rowState; //1 means pressed, 0 means released | read_pins_t rowState; //1 means pressed, 0 means released | ||||
uint8_t readPinCount; | |||||
//uint8_t readPinCount; | |||||
read_pins_t debouncedChanged; //1 means debounced changed | read_pins_t debouncedChanged; //1 means debounced changed | ||||
rowState = scanner.scan(readPinCount); | |||||
rowState = scanner.scan(); | |||||
debouncedChanged = debouncer.debounce(rowState, debounced); | debouncedChanged = debouncer.debounce(rowState, debounced); | ||||
pressRelease(readPinCount, debouncedChanged); | |||||
pressRelease(READ_PIN_COUNT, debouncedChanged); | |||||
} | } |
private: | private: | ||||
Scanner_uC scanner; | Scanner_uC scanner; | ||||
Debouncer_4Samples debouncer; | Debouncer_4Samples debouncer; | ||||
const uint8_t READ_PIN_COUNT; //number of read pins | |||||
public: | public: | ||||
Row_uC(const uint8_t strobePin, const uint8_t READ_PINS[], const uint8_t READ_PIN_COUNT, | Row_uC(const uint8_t strobePin, const uint8_t READ_PINS[], const uint8_t READ_PIN_COUNT, | ||||
Key *const ptrsKeys[]) | Key *const ptrsKeys[]) | ||||
: Row(ptrsKeys), scanner(strobePin, READ_PINS, READ_PIN_COUNT) { } | |||||
: Row(ptrsKeys), scanner(strobePin, READ_PINS, READ_PIN_COUNT), READ_PIN_COUNT(READ_PIN_COUNT) { } | |||||
void process(); | void process(); | ||||
}; | }; | ||||
#endif | #endif |
//constructor | //constructor | ||||
Scanner_ShiftRegs74HC165::Scanner_ShiftRegs74HC165(const uint8_t STROBE_PIN, uint8_t READ_PIN_COUNT) | Scanner_ShiftRegs74HC165::Scanner_ShiftRegs74HC165(const uint8_t STROBE_PIN, uint8_t READ_PIN_COUNT) | ||||
: STROBE_PIN(STROBE_PIN), BYTE_COUNT(ceil (float(READ_PIN_COUNT)/8)), READ_PIN_COUNT(READ_PIN_COUNT) | |||||
: STROBE_PIN(STROBE_PIN), BYTE_COUNT(ceil (float(READ_PIN_COUNT)/8)) | |||||
{ | { | ||||
//configure controller to communicate with shift register matrix | //configure controller to communicate with shift register matrix | ||||
pinMode(STROBE_PIN, OUTPUT); | pinMode(STROBE_PIN, OUTPUT); | ||||
/* | /* | ||||
Sets readPinCount and returns rowState. | Sets readPinCount and returns rowState. | ||||
*/ | */ | ||||
read_pins_t Scanner_ShiftRegs74HC165::scan(uint8_t& readPinCount) | |||||
read_pins_t Scanner_ShiftRegs74HC165::scan() | |||||
{ | { | ||||
read_pins_t rowState = 0; | read_pins_t rowState = 0; | ||||
//strobe row off | //strobe row off | ||||
digitalWrite(STROBE_PIN, STROBE_OFF); | digitalWrite(STROBE_PIN, STROBE_OFF); | ||||
readPinCount = READ_PIN_COUNT; | |||||
// readPinCount = READ_PIN_COUNT; | |||||
//for testing on breadboard, clear unpowered pins | //for testing on breadboard, clear unpowered pins | ||||
rowState &= 0b11110001000100010001000100010001; //todo | rowState &= 0b11110001000100010001000100010001; //todo |
static const bool STROBE_OFF; //logic level of strobe off, complement of active state | static const bool STROBE_OFF; //logic level of strobe off, complement of active state | ||||
const uint8_t STROBE_PIN; //Arduino pin number connected to this row | const uint8_t STROBE_PIN; //Arduino pin number connected to this row | ||||
const uint8_t BYTE_COUNT; //number of bytes to read from shift registers | const uint8_t BYTE_COUNT; //number of bytes to read from shift registers | ||||
uint8_t READ_PIN_COUNT; | |||||
//uint8_t READ_PIN_COUNT; | |||||
public: | public: | ||||
Scanner_ShiftRegs74HC165(const uint8_t STROBE_PIN, uint8_t READ_PIN_COUNT); | Scanner_ShiftRegs74HC165(const uint8_t STROBE_PIN, uint8_t READ_PIN_COUNT); | ||||
virtual read_pins_t scan(uint8_t& READ_PIN_COUNT); | |||||
virtual read_pins_t scan(); | |||||
void begin(); | void begin(); | ||||
}; | }; | ||||
#endif | #endif |
https://www.arduino.cc/en/Reference/DigitalRead | https://www.arduino.cc/en/Reference/DigitalRead | ||||
https://www.arduino.cc/en/Reference/Constants > Digital Pins modes: INPUT, INPUT_PULLUP, and OUTPUT | https://www.arduino.cc/en/Reference/Constants > Digital Pins modes: INPUT, INPUT_PULLUP, and OUTPUT | ||||
*/ | */ | ||||
read_pins_t Scanner_uC::scan(uint8_t& readPinCount) | |||||
read_pins_t Scanner_uC::scan() | |||||
{ | { | ||||
read_pins_t rowState = 0; //bitwise, one col per bit, 1 means key is pressed | read_pins_t rowState = 0; //bitwise, one col per bit, 1 means key is pressed | ||||
read_pins_t readMask = 1; //bitwise, one col per bit, active col bit is 1 | read_pins_t readMask = 1; //bitwise, one col per bit, active col bit is 1 | ||||
//strobe row off | //strobe row off | ||||
digitalWrite(STROBE_PIN, STROBE_OFF); | digitalWrite(STROBE_PIN, STROBE_OFF); | ||||
readPinCount = READ_PIN_COUNT; | |||||
// readPinCount = READ_PIN_COUNT; | |||||
return rowState; | return rowState; | ||||
} | } |
const uint8_t READ_PIN_COUNT; //number of read pins | const uint8_t READ_PIN_COUNT; //number of read pins | ||||
public: | public: | ||||
Scanner_uC(const uint8_t STROBE_PIN, | Scanner_uC(const uint8_t STROBE_PIN, | ||||
const uint8_t READ_PINS[], const uint8_t READ_PIN_COUNT); //todo rename READ_PIN_COUNT to READ_PIN_COUNT ?? | |||||
virtual read_pins_t scan(uint8_t& READ_PIN_COUNT); | |||||
const uint8_t READ_PINS[], const uint8_t READ_PIN_COUNT); | |||||
virtual read_pins_t scan(); | |||||
}; | }; | ||||
#endif | #endif | ||||