Skip to content

Instantly share code, notes, and snippets.

Created June 23, 2014 19:18
Show Gist options
  • Save anonymous/664e1c0636c04aee057a to your computer and use it in GitHub Desktop.
Save anonymous/664e1c0636c04aee057a to your computer and use it in GitHub Desktop.
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