Archived
1
0

update Scanner_ShiftRegsPISOMultiRow::scan(), rename LED_shiftRegs to LED_ShiftRegs

This commit is contained in:
wolfv6 2016-10-30 14:36:34 -06:00
parent 0c4b54db13
commit fa4f07cc9d
3 changed files with 18 additions and 24 deletions

View File

@ -1,8 +1,8 @@
#include "LED_shiftRegs.h"
#include "LED_ShiftRegs.h"
/* 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)
{
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().
Initializes shift register's shift/load pin.
*/
void LED_shiftRegs::begin()
void LED_ShiftRegs::begin()
{
SPI.begin();
digitalWrite(slaveSelect, HIGH);
}
//todo preserve other LED values, similar to Port_PCA9655E outputVal
void LED_shiftRegs::on()
void LED_ShiftRegs::on()
{
digitalWrite(slaveSelect, LOW);
SPI.transfer(pin);
digitalWrite (slaveSelect, HIGH);
}
void LED_shiftRegs::off()
void LED_ShiftRegs::off()
{
digitalWrite(slaveSelect, LOW);
SPI.transfer(0);

View File

@ -5,16 +5,16 @@
#include <SPI.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
*/
class LED_shiftRegs: public LEDInterface
class LED_ShiftRegs: public LEDInterface
{
private:
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
public:
LED_shiftRegs(const uint8_t slaveSelect, const uint8_t pin);
LED_ShiftRegs(const uint8_t slaveSelect, const uint8_t pin);
void begin();
virtual void on();
virtual void off();

View File

@ -16,7 +16,6 @@ Configures controller to communicate with shift register matrix.
void Scanner_ShiftRegsPISOMultiRow::init(const uint8_t strobePin)
{
pinMode(strobePin, OUTPUT);
//digitalWrite(strobePin, strobeOff);//todo is this needed?
}
/* 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
//strobe on
digitalWrite(strobePin, strobeOn);
//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, HIGH); //de-assert slave
//SPI.endTransaction();
digitalWrite(strobePin, strobeOn); //strobe on
//strobe off
digitalWrite(strobePin, strobeOff);
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.endTransaction();
return readState;
}