Question: How to implement the sequence in this code, using 5 shift register? int latchPin = 8; int clockPin = 12; int dataPin = 11; byte
How to implement the sequence in this code, using 5 shift register?
int latchPin = 8;
int clockPin = 12;
int dataPin = 11;
byte leds;
boolean trig = true;
unsigned char type;
void setup() {
//set pins to output so you can control the shift register
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop(){
if(trig){ type = LSBFIRST;}
else{ type = MSBFIRST;}
chaser();
trig = !trig;
//change the value of the boolean to control LEDs using a different bit order each run
}
void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, type, leds);
digitalWrite(latchPin, HIGH);
}
void chaser(){
leds = 0;
for(int i = 0; i <8;i++){
bitSet(leds,i);
if(i!=0){bitClear(leds,i-1);}
updateShiftRegister();
delay(100);
}
}
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
