update Scanner_ShiftRegsPISOMultiRow::scan(), rename LED_shiftRegs to LED_ShiftRegs
This commit is contained in:
parent
0c4b54db13
commit
fa4f07cc9d
@ -1,8 +1,8 @@
|
|||||||
#include "LED_shiftRegs.h"
|
#include "LED_ShiftRegs.h"
|
||||||
|
|
||||||
/* constructor
|
/* constructor
|
||||||
*/
|
*/
|
||||||
LED_shiftRegs::LED_shiftRegs(const uint8_t slaveSelect, const uint8_t pin)
|
LED_ShiftRegs::LED_ShiftRegs(const uint8_t slaveSelect, const uint8_t pin)
|
||||||
:slaveSelect(slaveSelect), pin(pin)
|
:slaveSelect(slaveSelect), pin(pin)
|
||||||
{
|
{
|
||||||
pinMode(slaveSelect, OUTPUT);
|
pinMode(slaveSelect, OUTPUT);
|
||||||
@ -11,21 +11,21 @@ LED_shiftRegs::LED_shiftRegs(const uint8_t slaveSelect, const uint8_t pin)
|
|||||||
/* begin() should be called once from sketch setup().
|
/* begin() should be called once from sketch setup().
|
||||||
Initializes shift register's shift/load pin.
|
Initializes shift register's shift/load pin.
|
||||||
*/
|
*/
|
||||||
void LED_shiftRegs::begin()
|
void LED_ShiftRegs::begin()
|
||||||
{
|
{
|
||||||
SPI.begin();
|
SPI.begin();
|
||||||
digitalWrite(slaveSelect, HIGH);
|
digitalWrite(slaveSelect, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
//todo preserve other LED values, similar to Port_PCA9655E outputVal
|
//todo preserve other LED values, similar to Port_PCA9655E outputVal
|
||||||
void LED_shiftRegs::on()
|
void LED_ShiftRegs::on()
|
||||||
{
|
{
|
||||||
digitalWrite(slaveSelect, LOW);
|
digitalWrite(slaveSelect, LOW);
|
||||||
SPI.transfer(pin);
|
SPI.transfer(pin);
|
||||||
digitalWrite (slaveSelect, HIGH);
|
digitalWrite (slaveSelect, HIGH);
|
||||||
}
|
}
|
||||||
|
|
||||||
void LED_shiftRegs::off()
|
void LED_ShiftRegs::off()
|
||||||
{
|
{
|
||||||
digitalWrite(slaveSelect, LOW);
|
digitalWrite(slaveSelect, LOW);
|
||||||
SPI.transfer(0);
|
SPI.transfer(0);
|
@ -5,16 +5,16 @@
|
|||||||
#include <SPI.h>
|
#include <SPI.h>
|
||||||
#include <LEDInterface.h>
|
#include <LEDInterface.h>
|
||||||
|
|
||||||
/* A LED_shiftRegs turns LED on and off.
|
/* A LED_ShiftRegs turns LED on and off.
|
||||||
shift register RCLK pin a.k.a. SS or ST
|
shift register RCLK pin a.k.a. SS or ST
|
||||||
*/
|
*/
|
||||||
class LED_shiftRegs: public LEDInterface
|
class LED_ShiftRegs: public LEDInterface
|
||||||
{
|
{
|
||||||
private:
|
private:
|
||||||
const uint8_t slaveSelect;//controller pin number connected to shift register RCLK
|
const uint8_t slaveSelect;//controller pin number connected to shift register RCLK
|
||||||
const uint8_t pin; //bit pattern, shift register pin that is connected to an LED
|
const uint8_t pin; //bit pattern, shift register pin that is connected to an LED
|
||||||
public:
|
public:
|
||||||
LED_shiftRegs(const uint8_t slaveSelect, const uint8_t pin);
|
LED_ShiftRegs(const uint8_t slaveSelect, const uint8_t pin);
|
||||||
void begin();
|
void begin();
|
||||||
virtual void on();
|
virtual void on();
|
||||||
virtual void off();
|
virtual void off();
|
@ -16,7 +16,6 @@ Configures controller to communicate with shift register matrix.
|
|||||||
void Scanner_ShiftRegsPISOMultiRow::init(const uint8_t strobePin)
|
void Scanner_ShiftRegsPISOMultiRow::init(const uint8_t strobePin)
|
||||||
{
|
{
|
||||||
pinMode(strobePin, OUTPUT);
|
pinMode(strobePin, OUTPUT);
|
||||||
//digitalWrite(strobePin, strobeOff);//todo is this needed?
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* begin() should be called once from sketch setup().
|
/* begin() should be called once from sketch setup().
|
||||||
@ -35,26 +34,21 @@ read_pins_t Scanner_ShiftRegsPISOMultiRow::scan(const uint8_t strobePin)
|
|||||||
{
|
{
|
||||||
read_pins_t readState = 0; //bits, 1 means key is pressed, 0 means released
|
read_pins_t readState = 0; //bits, 1 means key is pressed, 0 means released
|
||||||
|
|
||||||
//strobe on
|
|
||||||
digitalWrite(strobePin, strobeOn);
|
|
||||||
|
|
||||||
//SPI.beginTransaction( SPISettings(5000000, MSBFIRST, SPI_MODE0) ); //control SPI bus, 5 MHz
|
//SPI.beginTransaction( SPISettings(5000000, MSBFIRST, SPI_MODE0) ); //control SPI bus, 5 MHz
|
||||||
//digitalWrite(slaveSelect, LOW); //assert slave
|
|
||||||
|
|
||||||
delayMicroseconds(3); //time to stabilize photo-transistor todo needed?
|
|
||||||
delayMicroseconds(50); //todo for sr2_LEDs_strobe.ino
|
|
||||||
|
|
||||||
//read all the column pins
|
|
||||||
digitalWrite(slaveSelect, HIGH); //shift the data toward a serial output
|
|
||||||
|
|
||||||
SPI.transfer(&readState, byte_count);
|
|
||||||
digitalWrite(slaveSelect, LOW); //load parallel inputs to registers
|
digitalWrite(slaveSelect, LOW); //load parallel inputs to registers
|
||||||
|
|
||||||
//digitalWrite(slaveSelect, HIGH); //de-assert slave
|
digitalWrite(strobePin, strobeOn); //strobe on
|
||||||
//SPI.endTransaction();
|
|
||||||
|
|
||||||
//strobe off
|
delayMicroseconds(3); //time to stabilize photo-transistor todo need?
|
||||||
digitalWrite(strobePin, strobeOff);
|
delayMicroseconds(50); //todo for sr2_LEDs_strobe.ino
|
||||||
|
digitalWrite(slaveSelect, HIGH); //shift the data toward a serial output
|
||||||
|
|
||||||
|
digitalWrite(strobePin, strobeOff); //strobe off
|
||||||
|
|
||||||
|
SPI.transfer(&readState, byte_count);
|
||||||
|
|
||||||
|
//SPI.endTransaction();
|
||||||
|
|
||||||
return readState;
|
return readState;
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user