Created
June 23, 2014 19:18
-
-
Save anonymous/664e1c0636c04aee057a to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class ShiftRegister { | |
public: | |
ShiftRegister(uint8_t dataPin, uint8_t latchPin, uint8_t clockPin) { | |
pinMode(dataPin, OUTPUT); | |
pinMode(clockPin, OUTPUT); | |
pinMode(latchPin, OUTPUT); | |
} | |
void write() | |
{ | |
// turn off output | |
digitalWrite(latchPin, LOW); | |
// send states | |
shiftOut(dataPin, clockPin, MSBFIRST, state); | |
// turn on output | |
digitalWrite(latchPin, HIGH); | |
} | |
void set(uint8_t pin, uint8_t pinState, bool now=true) | |
{ | |
bitWrite(state, pin, pinState); | |
if (now) { | |
write(); | |
} | |
} | |
void clear() | |
{ | |
state = 0; | |
write(); | |
} | |
private: | |
byte state; | |
uint8_t dataPin, latchPin, clockPin; | |
}; | |
ShiftRegister shiftRegister(8, 9, 10); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment