// shift register turn signal in about 40 lines of code
// by Gray Mack
#define BUTTON_LEFT_PIN 3
#define BUTTON_RIGHT_PIN 4
#define DATA_PIN 8
#define CLOCK_PIN 9
#define LATCH_PIN 10
void setup() {
pinMode(BUTTON_LEFT_PIN, INPUT_PULLUP);
pinMode(BUTTON_RIGHT_PIN, INPUT_PULLUP);
pinMode(DATA_PIN, OUTPUT);
pinMode(CLOCK_PIN, OUTPUT);
pinMode(LATCH_PIN, OUTPUT);
}
byte shiftData = 0b00000000;
void loop() {
if(digitalRead(BUTTON_RIGHT_PIN) == LOW)
{
if(digitalRead(BUTTON_LEFT_PIN) == LOW)
{ // both
shiftData = 0b11111111;
}
else // just right
{
if(shiftData == 0b11111111)
shiftData = 0b00000000;
else
shiftData = (shiftData >> 1) + 0b10000000;
delay(50);
}
}
else if(digitalRead(BUTTON_LEFT_PIN) == LOW)
{ // just left
if(shiftData == 0b11111111)
shiftData = 0b00000000;
else
shiftData = (shiftData << 1) + 0b00000001;
delay(50);
}
else // no button pushed
{
shiftData = 0b00000000;
}
digitalWrite(LATCH_PIN, LOW);
shiftOut(DATA_PIN, CLOCK_PIN, MSBFIRST, shiftData);
digitalWrite(LATCH_PIN, HIGH);
}