diff --git a/examples/keybrd_shift_register/keybrd_shift_register.ino b/examples/keybrd_shift_register/keybrd_shift_register.ino index 438e760..d001391 100644 --- a/examples/keybrd_shift_register/keybrd_shift_register.ino +++ b/examples/keybrd_shift_register/keybrd_shift_register.ino @@ -126,7 +126,7 @@ const uint8_t LED_PIN = 16; //indicates wait //sometimes OS takes 6 seconds to recongnize keyboard, LED blinks from the begining void wait() { - for (uint8_t count = 0; count < 6; count++) + for (uint8_t count = 0; count < 7; count++) { //print count Keyboard.print(count); @@ -144,11 +144,12 @@ void setup() { pinMode (LED_PIN, OUTPUT); Keyboard.begin(); + + wait(); SPI.begin(); row_R0.begin(); row_R1.begin(); - wait(); Keyboard.print(F("keybrd_shift_reg.ino ")); debug.print_free_RAM(); } diff --git a/src/RowScanner_SPIShiftRegisters.cpp b/src/RowScanner_SPIShiftRegisters.cpp index 4b2c57c..00a6d6a 100644 --- a/src/RowScanner_SPIShiftRegisters.cpp +++ b/src/RowScanner_SPIShiftRegisters.cpp @@ -1,12 +1,17 @@ #include "RowScanner_SPIShiftRegisters.h" +//constructor +RowScanner_SPIShiftRegisters::RowScanner_SPIShiftRegisters(const uint8_t STROBE_PIN, uint8_t KEY_COUNT) + : STROBE_PIN(STROBE_PIN), ROW_END(1 << KEY_COUNT), BYTE_COUNT(ceil (float(KEY_COUNT)/8)) +{ + //configure controller to communicate with shift register matrix + pinMode(STROBE_PIN, OUTPUT); + pinMode(SHIFT_LOAD, OUTPUT); +} + void RowScanner_SPIShiftRegisters::begin() { - //configure row - pinMode(STROBE_PIN, OUTPUT); - //initialize shift register's shift/load pin - pinMode(SHIFT_LOAD, OUTPUT); digitalWrite(SHIFT_LOAD, HIGH); } @@ -29,7 +34,8 @@ read_pins_t RowScanner_SPIShiftRegisters::scan(read_pins_mask_t& rowEnd) //strobe row off digitalWrite(STROBE_PIN, LOW); - rowEnd = 1 << KEY_COUNT; + rowEnd = ROW_END; + //rowEnd = 1 << 8; //clear unpowered pins (for testing bb) todo rowState &= 0b01010001000100010001000100010001; //also 31st key diff --git a/src/RowScanner_SPIShiftRegisters.h b/src/RowScanner_SPIShiftRegisters.h index cd555f9..2ead3c1 100644 --- a/src/RowScanner_SPIShiftRegisters.h +++ b/src/RowScanner_SPIShiftRegisters.h @@ -33,11 +33,10 @@ class RowScanner_SPIShiftRegisters : public RowScannerInterface //todo static const bool ACTIVE_HIGH; //logic level of strobe pin: 0=activeLow, 1=activeHigh static const uint8_t SHIFT_LOAD; //controller's pin number that is connected to shift register's SHIFT_LOAD pin const uint8_t STROBE_PIN; //Arduino pin number connected to this row - const uint8_t KEY_COUNT; //number of keys in row + const read_pins_mask_t ROW_END; //number of keys in row + 1 const uint8_t BYTE_COUNT; //number of bytes to read from shift registers public: - RowScanner_SPIShiftRegisters(const uint8_t STROBE_PIN, uint8_t KEY_COUNT) - : STROBE_PIN(STROBE_PIN), KEY_COUNT(KEY_COUNT), BYTE_COUNT(ceil (float(KEY_COUNT)/8)) {} + RowScanner_SPIShiftRegisters(const uint8_t STROBE_PIN, uint8_t KEY_COUNT); virtual read_pins_t scan(read_pins_mask_t& rowEnd); void begin(); };