change RowScanner_SPIShiftRegisters to work with active high or active low
This commit is contained in:
parent
f5448b200a
commit
d5cbc3c58c
@ -37,6 +37,10 @@ const bool RowScanner_PinsArray::STROBE_OFF = HIGH;
|
||||
|
||||
const uint8_t RowScanner_SPIShiftRegisters::SHIFT_LOAD = 10;
|
||||
|
||||
//active state of right matrix
|
||||
const bool RowScanner_SPIShiftRegisters::STROBE_ON = LOW;
|
||||
const bool RowScanner_SPIShiftRegisters::STROBE_OFF = HIGH;
|
||||
|
||||
Debug debug;
|
||||
|
||||
// ================= LEFT PINS =================
|
||||
@ -144,7 +148,7 @@ Key* ptrsKeys_R0[] = { &s_0, &s_z, &s_z, &s_z, &s_1, &s_z, &s_z, &s_z,
|
||||
&s_4, &s_z, &s_z, &s_z, &s_5, &s_z, &s_z, &s_z,
|
||||
&s_6, &s_z, &s_z, &s_z, &s_3, &s_4, &s_5, &s_6 };
|
||||
const uint8_t KEY_R0_COUNT = sizeof(ptrsKeys_R0)/sizeof(*ptrsKeys_R0);
|
||||
Row_ShiftRegisters row_R0(8, ptrsKeys_R0, KEY_R0_COUNT);
|
||||
Row_ShiftRegisters row_R0(0, ptrsKeys_R0, KEY_R0_COUNT);
|
||||
|
||||
//prints a b c d u v w x
|
||||
Key* ptrsKeys_R1[] = { &s_a, &s_z, &s_z, &s_z, &s_b, &s_z, &s_z, &s_z,
|
||||
@ -152,7 +156,7 @@ Key* ptrsKeys_R1[] = { &s_a, &s_z, &s_z, &s_z, &s_b, &s_z, &s_z, &s_z,
|
||||
&s_e, &s_z, &s_z, &s_z, &s_f, &s_z, &s_z, &s_z,
|
||||
&s_g, &s_z, &s_z, &s_z, &s_u, &s_v, &s_w, &s_x };
|
||||
const uint8_t KEY_R1_COUNT = sizeof(ptrsKeys_R1)/sizeof(*ptrsKeys_R1);
|
||||
Row_ShiftRegisters row_R1(9, ptrsKeys_R1, KEY_R1_COUNT);
|
||||
Row_ShiftRegisters row_R1(1, ptrsKeys_R1, KEY_R1_COUNT);
|
||||
|
||||
// ################### MAIN ####################
|
||||
void setup()
|
||||
|
@ -12,11 +12,11 @@ Constructor is in RowScanner_PinsArray.cpp
|
||||
class RowScanner_PinsArray
|
||||
{
|
||||
private:
|
||||
static const bool STROBE_ON; //logic level of strobe on, HIGH or LOW
|
||||
static const bool STROBE_OFF; //logic level of strobe off, HIGH or LOW
|
||||
const uint8_t STROBE_PIN; //Arduino pin number connected to this row
|
||||
const uint8_t* const READ_PINS; //array of read pin numbers
|
||||
const uint8_t READ_PIN_COUNT; //number of read pins
|
||||
static const bool STROBE_ON; //logic level of strobe on, HIGH or LOW
|
||||
static const bool STROBE_OFF; //logic level of strobe off, complement of STROBE_ON
|
||||
const uint8_t STROBE_PIN; //Arduino pin number connected to this row
|
||||
const uint8_t* const READ_PINS; //array of read pin numbers
|
||||
const uint8_t READ_PIN_COUNT; //number of read pins
|
||||
public:
|
||||
RowScanner_PinsArray(const uint8_t STROBE_PIN,
|
||||
const uint8_t READ_PINS[], const uint8_t READ_PIN_COUNT); //todo rename READ_PIN_COUNT to KEY_COUNT ??
|
||||
|
@ -23,7 +23,7 @@ read_pins_t RowScanner_SPIShiftRegisters::scan(uint8_t& keyCount)
|
||||
read_pins_t rowState = 0;
|
||||
|
||||
//strobe row on
|
||||
digitalWrite(STROBE_PIN, HIGH);
|
||||
digitalWrite(STROBE_PIN, STROBE_ON);
|
||||
delayMicroseconds(3); //time to stablize voltage
|
||||
|
||||
//read all the column pins
|
||||
@ -32,7 +32,7 @@ read_pins_t RowScanner_SPIShiftRegisters::scan(uint8_t& keyCount)
|
||||
SPI.transfer(&rowState, BYTE_COUNT);
|
||||
|
||||
//strobe row off
|
||||
digitalWrite(STROBE_PIN, LOW);
|
||||
digitalWrite(STROBE_PIN, STROBE_OFF);
|
||||
|
||||
keyCount = KEY_COUNT;
|
||||
|
||||
|
@ -8,20 +8,29 @@
|
||||
#include <ColPort.h>
|
||||
|
||||
/* RowScanner_SPIShiftRegisters reads shift registers.
|
||||
shift registers 74HC165 Parallel-In-Serial-Out (PISO)
|
||||
shift registers 74HC165 is Parallel-In-Serial-Out (PISO)
|
||||
Upto 4 shift registers can be in a daisy chained.
|
||||
|
||||
in sketch:
|
||||
In sketch:
|
||||
const uint8_t RowScanner_SPIShiftRegisters::SHIFT_LOAD = 10;
|
||||
call begin() from setup()
|
||||
|
||||
Upto 4 shift registers can be in a daisy chained.
|
||||
For active low:
|
||||
const bool RowScanner_SPIShiftRegisters::STROBE_ON = LOW;
|
||||
const bool RowScanner_SPIShiftRegisters::STROBE_OFF = HIGH;
|
||||
//shift register parallel input pins have 10k pull-down resistors powered
|
||||
//controller's MISO pin is connected to shift register's complementary serial output (/QH) pin
|
||||
|
||||
The shift registers are active high:
|
||||
10k pull-down resistors are grounded
|
||||
connect controller's MISO pin to shift register's QH pin
|
||||
For active high:
|
||||
const bool RowScanner_SPIShiftRegisters::STROBE_ON = HIGH;
|
||||
const bool RowScanner_SPIShiftRegisters::STROBE_OFF = LOW;
|
||||
//shift register parallel input pins have 10k pull-down resistors grounded
|
||||
//controller's MISO pin is connected to shift register's serial output (QH) pin
|
||||
|
||||
The shift register needs 5 wires.
|
||||
In addition, each row needs to be connected to a strobe pin from controller.
|
||||
|
||||
todo move this to tutorial
|
||||
The shift register needs 5 wires.
|
||||
The two parts of a split keyboard can be connected by one of:
|
||||
* eSATA cable (has 7 wires, good for 2 rows)
|
||||
* Ethernet cable (has 8 wires, good for 3 rows)
|
||||
@ -31,6 +40,8 @@ class RowScanner_SPIShiftRegisters
|
||||
{
|
||||
private:
|
||||
static const uint8_t SHIFT_LOAD; //controller's pin number that is connected to shift register's SHIFT_LOAD pin
|
||||
static const bool STROBE_ON; //logic level of strobe on, active state HIGH or LOW
|
||||
static const bool STROBE_OFF; //logic level of strobe off, complement of active state
|
||||
const uint8_t STROBE_PIN; //Arduino pin number connected to this row
|
||||
const uint8_t BYTE_COUNT; //number of bytes to read from shift registers
|
||||
uint8_t KEY_COUNT;
|
||||
|
Reference in New Issue
Block a user