Arhivēts
1
0
Šis repozitorijs ir arhivēts. Ir iespējams aplūkot tā failus un to konēt, bet nav iespējams iesūtīt izmaiņas, kā arī izveidot jaunas problēmas vai izmaiņu pieprasījumus.
keybrd/src/Scanner_ShiftRegsReadStrobed.h

62 rindas
2.5 KiB
C

2016-11-04 06:56:26 +00:00
#ifndef ROWSCANNER_SHIFTREGSREADSTROBED_H
#define ROWSCANNER_SHIFTREGSREADSTROBED_H
2016-09-25 04:27:06 +00:00
#include <Arduino.h>
#include <inttypes.h>
#include <config_keybrd.h>
#include <SPI.h>
#include <ScannerInterface.h>
/* Scanner_ShiftRegsReadStrobed reads shift registers.
Shift registers can be daisy chained for a total of 32 read pins.
2016-11-04 06:56:26 +00:00
This was tested on 74HC165 shift registers, which are Parallel-In-Serial-Out (PISO).
The class works with machanical switches or photointerrupter switches.
A "strobe" powers the IR LEDs for a short time while the shift registers read the photo transistors.
The IR LEDs are off most of the time to preserve IR LED life.
2016-09-25 04:27:06 +00:00
Example instantiation:
2016-11-04 06:56:26 +00:00
Scanner_ShiftRegsReadStrobed scanner_R(HIGH, 6, 4);
2016-09-25 04:27:06 +00:00
There are three Scanner_ShiftRegsReadStrobed parameters.
2016-11-06 09:41:56 +00:00
1. "activeState" paramter is active state HIGH or LOW.
2016-11-04 06:56:26 +00:00
2. "slaveSelect" paramter is controller pin connected to shift register's SHIFT-LOAD pin.
3. "byte_count" is the number of bytes to read from shift registers (1 to 4).
byte_count should cover all the row's keys: byte_count*8 >= row's keyCount
2016-09-25 04:27:06 +00:00
Hardware setup:
2016-11-04 06:56:26 +00:00
Each row of keys is connected to a controller by 6 wires:
* GND
* power
* CLK
* Slave Select
* MISO
* strobe
2016-09-25 04:27:06 +00:00
For active low:
Shift-register parallel-input pins need 10k Ohm pull-up resistors powered.
Orient diodes with cathode (banded end) towards the write pins (row)
Controller's MISO pin is connected to shift register's complementary serial output (/QH) pin
For active high:
Shift-register parallel-input pins need 10k pull-down resistors grounded.
Orient diodes with cathode (banded end) towards the read pins.
Controller's MISO pin is connected to shift register's serial output (QH) pin
2016-11-04 06:56:26 +00:00
If multiple rows (or any SPI divice) share a MISO line, the shift registers need to be isolated by a tri-state buffer chip.
2016-09-25 04:27:06 +00:00
*/
class Scanner_ShiftRegsReadStrobed : public ScannerInterface
2016-09-25 04:27:06 +00:00
{
private:
2016-11-06 09:41:56 +00:00
const bool activeState; //logic level of strobe on, active state HIGH or LOW
2016-09-28 20:37:40 +00:00
const uint8_t slaveSelect;//controller pin number connected to shift register SHIFT-LOAD pin
2016-09-25 04:27:06 +00:00
const uint8_t byte_count; //number of bytes to read from shift registers
public:
2016-11-06 09:41:56 +00:00
Scanner_ShiftRegsReadStrobed(const bool activeState,
2016-09-28 20:37:40 +00:00
const uint8_t slaveSelect, const uint8_t byte_count);
2016-09-25 04:27:06 +00:00
virtual void init(const uint8_t strobePin);
virtual void begin();
virtual read_pins_t scan(const uint8_t strobePin);
};
#endif