Debouncer_4Samples debouncer; | Debouncer_4Samples debouncer; | ||||
public: | public: | ||||
//Row constructor was like Row_DH constructor | //Row constructor was like Row_DH constructor | ||||
Row(Key *const ptrsKeys[]) : RowBase(ptrsKeys) { } | |||||
Row(const uint8_t rowPin, Key *const ptrsKeys[]) : RowBase(ptrsKeys), scanner(rowPin) { } | |||||
virtual void process(); | virtual void process(); | ||||
}; | }; | ||||
#endif | #endif |
Avoid sampling the switch input at a rate synchronous to events in the environment | Avoid sampling the switch input at a rate synchronous to events in the environment | ||||
that might create periodic EMI. For instance, 50 and 60 Hz. | that might create periodic EMI. For instance, 50 and 60 Hz. | ||||
The largest allowabl DELAY_MICROSECONDS is 65535 (.065535 second). | |||||
Polling I2C may slow the scan rate enough so that no additional delay is needed: | Polling I2C may slow the scan rate enough so that no additional delay is needed: | ||||
const unsigned int Row::DELAY_MICROSECONDS = 0; | const unsigned int Row::DELAY_MICROSECONDS = 0; | ||||
Slow-scan trick for debug messages that print too fast: | |||||
change DELAY_MICROSECONDS to a large number like 10000 | |||||
Slow-scan trick for debug messages that print too fast, add delay: | |||||
delay(1000); | |||||
That way debug messages are printed at a managable rate. | That way debug messages are printed at a managable rate. | ||||
*/ | */ | ||||
void RowBase::wait() | void RowBase::wait() |
#include "RowScanner_Arduino.h" | #include "RowScanner_Arduino.h" | ||||
/* | /* | ||||
Strobes the row and reads the columns. | Strobes the row and reads the columns. | ||||
Strobe is on for shortest possible time to preserve IR LED on DodoHand's optic switch. | |||||
Strobe is on for shortest possible time. | |||||
*/ | */ | ||||
uint8_t RowScanner_Arduino::scan(uint16_t& rowEnd) | uint8_t RowScanner_Arduino::scan(uint16_t& rowEnd) | ||||
{ | { | ||||
//strobe row on | //strobe row on | ||||
if (activeHigh) | if (activeHigh) | ||||
{ | { | ||||
digitalWrite(0, HIGH); | |||||
digitalWrite(stobePin, HIGH); | |||||
} | } | ||||
else //activeLow | else //activeLow | ||||
{ | { | ||||
digitalWrite(0, LOW); | |||||
digitalWrite(stobePin, LOW); | |||||
} | } | ||||
delayMicroseconds(3); //time to stablize voltage | delayMicroseconds(3); //time to stablize voltage | ||||
#include <ColPort.h> | #include <ColPort.h> | ||||
/* rowPin > stobePins[] | /* rowPin > stobePins[] | ||||
replace port calls with | replace port calls with | ||||
x pass 1: hard coded pins for row0 and col6, init in setup() | |||||
x pass 1: hard code pins for row0 and col6, init in setup() | |||||
pass 2: pins[] array - first strobe, then read | pass 2: pins[] array - first strobe, then read | ||||
pass 3: move calls to IC classes - Strobe_uC, Read_uC | pass 3: move calls to IC classes - Strobe_uC, Read_uC | ||||
pass 4: add IC classes Strobe_MCP23018, Read_MCP23018 */ | pass 4: add IC classes Strobe_MCP23018, Read_MCP23018 */ | ||||
{ | { | ||||
private: | private: | ||||
static const bool activeHigh; //logic level of strobe pin: 0=activeLow, 1=activeHigh | static const bool activeHigh; //logic level of strobe pin: 0=activeLow, 1=activeHigh | ||||
//const uint8_t* stobePins; //array of strobe pins | |||||
const uint8_t stobePin; //Arduino pin number connected to this row | |||||
//const uint8_t* readPins; //array of read pins | //const uint8_t* readPins; //array of read pins | ||||
//const uint8_t readPinCount; | //const uint8_t readPinCount; | ||||
public: | public: | ||||
/*RowScanner_Arduino() | |||||
: | |||||
readPinCount(readPinCount) {}*/ | |||||
RowScanner_Arduino(const uint8_t stobePin) | |||||
: stobePin(stobePin) | |||||
// readPinCount(readPinCount) | |||||
{} | |||||
virtual uint8_t scan(uint16_t& rowEnd); | virtual uint8_t scan(uint16_t& rowEnd); | ||||
uint8_t getRowState(uint16_t& rowEnd); | uint8_t getRowState(uint16_t& rowEnd); | ||||
}; | }; |