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;
|
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;
|
Debug debug;
|
||||||
|
|
||||||
// ================= LEFT PINS =================
|
// ================= 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_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 };
|
&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);
|
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
|
//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,
|
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_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 };
|
&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);
|
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 ####################
|
// ################### MAIN ####################
|
||||||
void setup()
|
void setup()
|
||||||
|
@ -13,7 +13,7 @@ class RowScanner_PinsArray
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static const bool STROBE_ON; //logic level of strobe on, HIGH or LOW
|
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
|
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 STROBE_PIN; //Arduino pin number connected to this row
|
||||||
const uint8_t* const READ_PINS; //array of read pin numbers
|
const uint8_t* const READ_PINS; //array of read pin numbers
|
||||||
const uint8_t READ_PIN_COUNT; //number of read pins
|
const uint8_t READ_PIN_COUNT; //number of read pins
|
||||||
|
@ -23,7 +23,7 @@ read_pins_t RowScanner_SPIShiftRegisters::scan(uint8_t& keyCount)
|
|||||||
read_pins_t rowState = 0;
|
read_pins_t rowState = 0;
|
||||||
|
|
||||||
//strobe row on
|
//strobe row on
|
||||||
digitalWrite(STROBE_PIN, HIGH);
|
digitalWrite(STROBE_PIN, STROBE_ON);
|
||||||
delayMicroseconds(3); //time to stablize voltage
|
delayMicroseconds(3); //time to stablize voltage
|
||||||
|
|
||||||
//read all the column pins
|
//read all the column pins
|
||||||
@ -32,7 +32,7 @@ read_pins_t RowScanner_SPIShiftRegisters::scan(uint8_t& keyCount)
|
|||||||
SPI.transfer(&rowState, BYTE_COUNT);
|
SPI.transfer(&rowState, BYTE_COUNT);
|
||||||
|
|
||||||
//strobe row off
|
//strobe row off
|
||||||
digitalWrite(STROBE_PIN, LOW);
|
digitalWrite(STROBE_PIN, STROBE_OFF);
|
||||||
|
|
||||||
keyCount = KEY_COUNT;
|
keyCount = KEY_COUNT;
|
||||||
|
|
||||||
|
@ -8,20 +8,29 @@
|
|||||||
#include <ColPort.h>
|
#include <ColPort.h>
|
||||||
|
|
||||||
/* RowScanner_SPIShiftRegisters reads shift registers.
|
/* 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;
|
const uint8_t RowScanner_SPIShiftRegisters::SHIFT_LOAD = 10;
|
||||||
call begin() from setup()
|
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:
|
For active high:
|
||||||
10k pull-down resistors are grounded
|
const bool RowScanner_SPIShiftRegisters::STROBE_ON = HIGH;
|
||||||
connect controller's MISO pin to shift register's QH pin
|
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.
|
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:
|
The two parts of a split keyboard can be connected by one of:
|
||||||
* eSATA cable (has 7 wires, good for 2 rows)
|
* eSATA cable (has 7 wires, good for 2 rows)
|
||||||
* Ethernet cable (has 8 wires, good for 3 rows)
|
* Ethernet cable (has 8 wires, good for 3 rows)
|
||||||
@ -31,6 +40,8 @@ class RowScanner_SPIShiftRegisters
|
|||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
static const uint8_t SHIFT_LOAD; //controller's pin number that is connected to shift register's SHIFT_LOAD pin
|
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 STROBE_PIN; //Arduino pin number connected to this row
|
||||||
const uint8_t BYTE_COUNT; //number of bytes to read from shift registers
|
const uint8_t BYTE_COUNT; //number of bytes to read from shift registers
|
||||||
uint8_t KEY_COUNT;
|
uint8_t KEY_COUNT;
|
||||||
|
Reference in New Issue
Block a user