2016-06-06 20:23:40 +00:00
|
|
|
#include "RowScanner_Arduino.h"
|
|
|
|
/*
|
|
|
|
Strobes the row and reads the columns.
|
|
|
|
*/
|
|
|
|
uint8_t RowScanner_Arduino::scan(uint16_t& rowEnd)
|
|
|
|
{
|
|
|
|
uint8_t rowState = 0;
|
2016-06-07 01:37:48 +00:00
|
|
|
uint8_t col = 1;
|
2016-06-06 20:23:40 +00:00
|
|
|
|
|
|
|
//strobe row on
|
|
|
|
if (activeHigh)
|
|
|
|
{
|
2016-06-06 21:11:19 +00:00
|
|
|
digitalWrite(stobePin, HIGH);
|
2016-06-06 20:23:40 +00:00
|
|
|
}
|
|
|
|
else //activeLow
|
|
|
|
{
|
2016-06-06 21:11:19 +00:00
|
|
|
digitalWrite(stobePin, LOW);
|
2016-06-06 20:23:40 +00:00
|
|
|
}
|
|
|
|
delayMicroseconds(3); //time to stablize voltage
|
|
|
|
|
|
|
|
//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
|
|
|
{
|
|
|
|
rowState |= col;
|
|
|
|
}
|
2016-06-07 01:37:48 +00:00
|
|
|
/*
|
|
|
|
Keyboard.print(" stobePin");
|
|
|
|
Keyboard.print(stobePin);
|
|
|
|
Keyboard.print(" readPins[");
|
|
|
|
Keyboard.print(i);
|
|
|
|
Keyboard.print("]");
|
|
|
|
Keyboard.print((int)readPins[i]);
|
|
|
|
Keyboard.print(" col");
|
|
|
|
Keyboard.print(col);
|
|
|
|
Keyboard.print(" ");
|
|
|
|
*/
|
2016-06-06 20:23:40 +00:00
|
|
|
col <<= 1;
|
|
|
|
}
|
|
|
|
|
|
|
|
//strobe row off
|
|
|
|
if (activeHigh)
|
|
|
|
{
|
|
|
|
digitalWrite(0, LOW);
|
|
|
|
}
|
|
|
|
else //activeLow
|
|
|
|
{
|
|
|
|
digitalWrite(0, HIGH);
|
|
|
|
}
|
|
|
|
|
|
|
|
rowEnd = 4; //only read first two col, a1 b2 4
|
|
|
|
|
2016-06-07 01:37:48 +00:00
|
|
|
//Keyboard.print(rowState);
|
2016-06-06 20:23:40 +00:00
|
|
|
return rowState;
|
|
|
|
}
|