@@ -2,7 +2,6 @@ | |||
#define LED_PORT_H | |||
#include <Arduino.h> | |||
#include <inttypes.h> | |||
#include <Wire.h> | |||
#include <LEDInterface.h> | |||
#include <PortInterface.h> | |||
@@ -0,0 +1,11 @@ | |||
#include "LED_ShiftReg.h" | |||
void LED_ShiftReg::on() | |||
{ | |||
refPort.write(pin, HIGH); | |||
} | |||
void LED_ShiftReg::off() | |||
{ | |||
refPort.write(pin, LOW); | |||
} |
@@ -0,0 +1,22 @@ | |||
#ifndef LED_SHIFTREG_H | |||
#define LED_SHIFTREG_H | |||
#include <Arduino.h> | |||
#include <inttypes.h> | |||
#include <LEDInterface.h> | |||
#include <PortWriteInterface.h> | |||
/* LED_ShiftReg turns LED on and off. | |||
shift register RCLK pin a.k.a. SS or ST | |||
*/ | |||
class LED_ShiftReg: public LEDInterface | |||
{ | |||
private: | |||
PortWriteInterface& refPort; | |||
const uint8_t pin; //bit pattern, 1 is shift-register pin connected to an LED | |||
public: | |||
LED_ShiftReg(PortWriteInterface& refPort, uint8_t pin) | |||
: refPort(refPort), pin(pin) {} | |||
virtual void on(); | |||
virtual void off(); | |||
}; | |||
#endif |
@@ -1,33 +0,0 @@ | |||
#include "LED_ShiftRegs.h" | |||
/* constructor | |||
*/ | |||
LED_ShiftRegs::LED_ShiftRegs(const uint8_t slaveSelect, const uint8_t pin) | |||
:slaveSelect(slaveSelect), pin(pin) | |||
{ | |||
pinMode(slaveSelect, OUTPUT); | |||
} | |||
/* begin() should be called once from sketch setup(). | |||
Initializes shift register's shift/load pin. | |||
*/ | |||
void LED_ShiftRegs::begin() | |||
{ | |||
SPI.begin(); | |||
digitalWrite(slaveSelect, HIGH); | |||
} | |||
//todo preserve other LED values, similar to Port_PCA9655E outputVal | |||
void LED_ShiftRegs::on() | |||
{ | |||
digitalWrite(slaveSelect, LOW); | |||
SPI.transfer(pin); | |||
digitalWrite (slaveSelect, HIGH); | |||
} | |||
void LED_ShiftRegs::off() | |||
{ | |||
digitalWrite(slaveSelect, LOW); | |||
SPI.transfer(0); | |||
digitalWrite (slaveSelect, HIGH); | |||
} |
@@ -1,22 +0,0 @@ | |||
#ifndef LED_SHIFTREGS_H | |||
#define LED_SHIFTREGS_H | |||
#include <Arduino.h> | |||
#include <inttypes.h> | |||
#include <SPI.h> | |||
#include <LEDInterface.h> | |||
/* A LED_ShiftRegs turns LED on and off. | |||
shift register RCLK pin a.k.a. SS or ST | |||
*/ | |||
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); | |||
void begin(); | |||
virtual void on(); | |||
virtual void off(); | |||
}; | |||
#endif |
@@ -0,0 +1,11 @@ | |||
#ifndef PORTWRITEINTERFACE_H | |||
#define PORTWRITEINTERFACE_H | |||
#include <Arduino.h> | |||
#include <inttypes.h> | |||
class PortWriteInterface | |||
{ | |||
public: | |||
virtual void write(const uint8_t pin, const bool pinLogicLevel)=0; | |||
}; | |||
#endif |
@@ -0,0 +1,31 @@ | |||
#include "Port_ShiftRegs.h" | |||
Port_ShiftRegs::Port_ShiftRegs(const uint8_t slaveSelect) : slaveSelect(slaveSelect) | |||
{ | |||
pinMode(slaveSelect, OUTPUT); | |||
} | |||
/* begin() should be called once from sketch setup(). | |||
Initializes shift register's shift/load pin. | |||
*/ | |||
void Port_ShiftRegs::begin() | |||
{ | |||
digitalWrite(slaveSelect, HIGH); | |||
SPI.begin(); | |||
} | |||
void Port_ShiftRegs::write(const uint8_t pin, const bool logicLevel) | |||
{ | |||
if (logicLevel == LOW) | |||
{ | |||
outputVal &= ~pin; //set pin output to low | |||
} | |||
else | |||
{ | |||
outputVal |= pin; //set pin output to high | |||
} | |||
digitalWrite(slaveSelect, LOW); | |||
SPI.transfer(outputVal); | |||
digitalWrite (slaveSelect, HIGH); | |||
} |
@@ -0,0 +1,21 @@ | |||
#ifndef PORT_SHIFTREGS_H | |||
#define PORT_SHIFTREGS_H | |||
#include <Arduino.h> | |||
#include <inttypes.h> | |||
#include <SPI.h> | |||
#include <PortWriteInterface.h> | |||
/* Port_ShiftRegs | |||
shift register RCLK pin a.k.a. SS or ST | |||
*/ | |||
class Port_ShiftRegs : public PortWriteInterface | |||
{ | |||
private: | |||
const uint8_t slaveSelect; //controller-pin number connected to shift register RCLK | |||
uint8_t outputVal; //bit pattern for LEDs | |||
public: | |||
Port_ShiftRegs(const uint8_t slaveSelect); | |||
void begin(); | |||
void write(const uint8_t pin, const bool logicLevel); | |||
}; | |||
#endif |
@@ -1,7 +1,5 @@ | |||
#include "Scanner_ShiftRegsPISOMultiRow.h" | |||
/* constructor | |||
*/ | |||
Scanner_ShiftRegsPISOMultiRow::Scanner_ShiftRegsPISOMultiRow(const bool strobeOn, | |||
const uint8_t slaveSelect, const uint8_t byte_count) | |||
: strobeOn(strobeOn), strobeOff(!strobeOn), |