-
Notifications
You must be signed in to change notification settings - Fork 14
/
Copy pathPort_ShiftRegs.cpp
39 lines (33 loc) · 974 Bytes
/
Port_ShiftRegs.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
#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();
}
/* writeLow() sets pin output LOW.
pin is bit pattern, where pin being set is 1.
*/
void Port_ShiftRegs::writeLow(const uint8_t pin)
{
outputVal &= ~pin; //set pin output to low
digitalWrite(slaveSelect, LOW);
SPI.transfer(outputVal);
digitalWrite (slaveSelect, HIGH);
}
/* writeHigh() sets pin output HIGH.
pin is bit pattern, where pin being set is 1.
*/
void Port_ShiftRegs::writeHigh(const uint8_t pin)
{
outputVal |= pin; //set pin output to high
digitalWrite(slaveSelect, LOW);
SPI.transfer(outputVal);
digitalWrite (slaveSelect, HIGH);
}