Hardware: Arduino UNO
So I am new to shift registers and I am looking to convert my current code into shift register code to free up pins. At its current state, it sweeps the LEDs right then left, then goes to another script and that chooses a random number and then tells the shift register to sweep up to that particular LED and stop. What I am trying to do is make that LED that the random number chooses and make it blink. With my original code, I could just use digitalWrite(something, LOW) to turn it off and the opposite to turn it back on. How do I replicate that in shift register language? Thanks for any help I can receive!
const int tDelay = 25;
const int dataPin = 12;
const int latchPin = 11;
const int clockPin = 9;
bool DirectionState = 0;
long randNumber;
int number = 0;
int count = 0;
int reLoop = true;
void updateShiftRegister(unsigned int leds, bool isMSBFIRST = false) {
byte lowLED = lowByte(leds);
byte highLED = highByte(leds);
digitalWrite(latchPin, LOW);
if (isMSBFIRST == false) {
shiftOut(dataPin, clockPin, LSBFIRST, lowLED);
shiftOut(dataPin, clockPin, LSBFIRST, highLED);
} else {
shiftOut(dataPin, clockPin, MSBFIRST, highLED);
shiftOut(dataPin, clockPin, MSBFIRST, lowLED);
}
digitalWrite(latchPin, HIGH);
}
void setup() {
// put your setup code here, to run once:
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
randomSeed(analogRead(0));
}
void loop() {
if (reLoop == true) {
unsigned int leds = 0B0000000000000000;
if (count < 2) {
for (int i = 0; i < 16; i++) {
leds = 0B0000000000000000;
bitSet(leds, i);
updateShiftRegister(leds, DirectionState);
delay(tDelay);
}
count += 1;
}
DirectionState = !DirectionState;
numberPicker();
}
}
void numberPicker() {
if (count == 2) {
unsigned int leds = 0B0000000000000000;
randNumber = random(1, 15);
for (int i = 0; i < randNumber; i++) {
leds = 0B0000000000000000;
bitSet(leds, i);
updateShiftRegister(leds);
delay(25);
}
number = randNumber;
reLoop = false;
colorSelect();
}
}
void colorSelect() {
digitalWrite(latchPin, LOW);
for (int i = 0; i < 4; i++) {
}
}