#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); | ||||
/* 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); |
#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(); |
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(). | ||||
{ | { | ||||
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 | |||||
digitalWrite(slaveSelect, LOW); //load parallel inputs to registers | |||||
digitalWrite(strobePin, strobeOn); //strobe on | |||||
//read all the column pins | |||||
digitalWrite(slaveSelect, HIGH); //shift the data toward a serial output | |||||
delayMicroseconds(3); //time to stabilize photo-transistor todo need? | |||||
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.transfer(&readState, byte_count); | ||||
digitalWrite(slaveSelect, LOW); //load parallel inputs to registers | |||||
//digitalWrite(slaveSelect, HIGH); //de-assert slave | |||||
//SPI.endTransaction(); | //SPI.endTransaction(); | ||||
//strobe off | |||||
digitalWrite(strobePin, strobeOff); | |||||
return readState; | return readState; | ||||
} | } | ||||