2016-06-06 20:23:40 +00:00
|
|
|
#include "RowScanner_Arduino.h"
|
2016-06-07 09:26:25 +00:00
|
|
|
|
2016-06-06 20:23:40 +00:00
|
|
|
/*
|
|
|
|
Strobes the row and reads the columns.
|
2016-06-08 02:24:50 +00:00
|
|
|
Sets rowEnd and returns rowState.
|
|
|
|
rowEnd is a bitwise row mask, one col per bit, where active col bit is 1.
|
|
|
|
At end of function, 1 bit marks place immediatly after last key of row.
|
|
|
|
rowEnd is a larger type than portMask so that it can not overflow.
|
2016-06-06 20:23:40 +00:00
|
|
|
*/
|
|
|
|
uint8_t RowScanner_Arduino::scan(uint16_t& rowEnd)
|
|
|
|
{
|
|
|
|
uint8_t rowState = 0;
|
2016-06-08 02:24:50 +00:00
|
|
|
rowEnd = 1;
|
2016-06-06 20:23:40 +00:00
|
|
|
|
|
|
|
//strobe row on
|
|
|
|
if (activeHigh)
|
|
|
|
{
|
2016-06-07 09:26:25 +00:00
|
|
|
digitalWrite(strobePin, HIGH);
|
2016-06-06 20:23:40 +00:00
|
|
|
}
|
|
|
|
else //activeLow
|
|
|
|
{
|
2016-06-07 09:26:25 +00:00
|
|
|
digitalWrite(strobePin, LOW);
|
2016-06-06 20:23:40 +00:00
|
|
|
}
|
2016-06-08 02:24:50 +00:00
|
|
|
delayMicroseconds(3); //time to stablize voltage
|
2016-06-07 09:26:25 +00:00
|
|
|
|
2016-06-06 20:23:40 +00:00
|
|
|
//read all the column ports
|
2016-06-07 01:37:48 +00:00
|
|
|
for (uint8_t i=0; i < READ_PIN_COUNT; i++)
|
2016-06-06 20:23:40 +00:00
|
|
|
{
|
2016-06-07 01:37:48 +00:00
|
|
|
if ( digitalRead(readPins[i]) == activeHigh )
|
2016-06-06 20:23:40 +00:00
|
|
|
{
|
2016-06-08 02:24:50 +00:00
|
|
|
rowState |= rowEnd;
|
2016-06-06 20:23:40 +00:00
|
|
|
}
|
2016-06-08 02:24:50 +00:00
|
|
|
rowEnd <<= 1;
|
2016-06-06 20:23:40 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
//strobe row off
|
|
|
|
if (activeHigh)
|
|
|
|
{
|
2016-06-07 09:26:25 +00:00
|
|
|
digitalWrite(strobePin, LOW);
|
2016-06-06 20:23:40 +00:00
|
|
|
}
|
|
|
|
else //activeLow
|
|
|
|
{
|
2016-06-07 09:26:25 +00:00
|
|
|
digitalWrite(strobePin, HIGH);
|
2016-06-06 20:23:40 +00:00
|
|
|
}
|
2016-06-08 02:24:50 +00:00
|
|
|
|
2016-06-06 20:23:40 +00:00
|
|
|
return rowState;
|
|
|
|
}
|