2016-09-25 04:27:06 +00:00
|
|
|
#include "Scanner_ShiftRegsPISOMultiRow.h"
|
|
|
|
|
|
|
|
Scanner_ShiftRegsPISOMultiRow::Scanner_ShiftRegsPISOMultiRow(const bool strobeOn,
|
|
|
|
const uint8_t slaveSelect, const uint8_t byte_count)
|
|
|
|
: strobeOn(strobeOn), strobeOff(!strobeOn),
|
2016-09-28 20:37:40 +00:00
|
|
|
slaveSelect(slaveSelect), byte_count(byte_count)
|
2016-09-25 04:27:06 +00:00
|
|
|
{
|
|
|
|
pinMode(slaveSelect, OUTPUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* init() is called once for each row from Row constructor.
|
|
|
|
Configures controller to communicate with shift register matrix.
|
|
|
|
*/
|
|
|
|
void Scanner_ShiftRegsPISOMultiRow::init(const uint8_t strobePin)
|
|
|
|
{
|
|
|
|
pinMode(strobePin, OUTPUT);
|
|
|
|
}
|
|
|
|
|
|
|
|
/* begin() should be called once from sketch setup().
|
|
|
|
Initializes shift register's shift/load pin.
|
|
|
|
*/
|
|
|
|
void Scanner_ShiftRegsPISOMultiRow::begin()
|
|
|
|
{
|
2016-10-30 08:30:13 +00:00
|
|
|
SPI.begin();
|
2016-09-25 04:27:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/* scan() strobes the row's strobePin and returns state of the shift register's input pins.
|
|
|
|
strobePin is Arduino pin number connected to this row.
|
|
|
|
Bit patterns are 1 bit per key.
|
|
|
|
*/
|
|
|
|
read_pins_t Scanner_ShiftRegsPISOMultiRow::scan(const uint8_t strobePin)
|
|
|
|
{
|
|
|
|
read_pins_t readState = 0; //bits, 1 means key is pressed, 0 means released
|
|
|
|
|
2016-10-30 08:30:13 +00:00
|
|
|
//SPI.beginTransaction( SPISettings(5000000, MSBFIRST, SPI_MODE0) ); //control SPI bus, 5 MHz
|
|
|
|
|
2016-10-30 20:36:34 +00:00
|
|
|
digitalWrite(slaveSelect, LOW); //load parallel inputs to registers
|
|
|
|
|
|
|
|
digitalWrite(strobePin, strobeOn); //strobe on
|
2016-09-25 04:27:06 +00:00
|
|
|
|
2016-10-30 20:36:34 +00:00
|
|
|
delayMicroseconds(3); //time to stabilize photo-transistor todo need?
|
|
|
|
delayMicroseconds(50); //todo for sr2_LEDs_strobe.ino
|
|
|
|
digitalWrite(slaveSelect, HIGH); //shift the data toward a serial output
|
|
|
|
|
|
|
|
digitalWrite(strobePin, strobeOff); //strobe off
|
2016-10-30 08:30:13 +00:00
|
|
|
|
2016-09-25 04:27:06 +00:00
|
|
|
SPI.transfer(&readState, byte_count);
|
2016-10-30 08:30:13 +00:00
|
|
|
|
|
|
|
//SPI.endTransaction();
|
2016-09-25 04:27:06 +00:00
|
|
|
|
|
|
|
return readState;
|
|
|
|
}
|
|
|
|
|