I have a switch register connected to a Uno R3 and 5 LED (there will be more).
How do you use a pattern code so only one comes on and stays on.
*/
//Define the pins for the switch register
int latchPin = 5;
int clockPin = 6;
int dataPin = 4;
//int seq1[14] = {1,2,4,8,16,32,64,128,64,32,16,8,4,2}; //The array for storing byte #1
int seq1[5] = {1,2,1,2,1}; //The array for storing the byte #1 value
int seq2[5] = {0,0,0,0,0}; //The array for storing the byte #2 value
byte leds = 0;
void setup()
{
// Setup Serial Monitor
Serial.begin(9600);
//Configure each IO pin
pinMode(latchPin, OUTPUT);
pinMode(dataPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}////////////////////////////////////////////////////////////////////////END
void loop()
{
leds = 0;
do_Clear_All();
for (int i = 0; i < 5; i++)// turn them on based on the sequence in the array
{
bitSet(leds, i);
updateShiftRegister();
do_Update_Sequence();
delay(500);
}
}////////////////////////////////////////////////////////////////////////END
void updateShiftRegister()
{
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, leds);
digitalWrite(latchPin, HIGH);
do_Print();
}////////////////////////////////////////////////////////////////////////END
void do_Print()
{
// Print to serial monitor
Serial.print("Pin States:\r\n");
Serial.println(leds);
delay(200);
}
void do_Update_Sequence()
{
for (int x = 0; x < 5; x++) //Array Index
{
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data
shiftOut(dataPin, clockPin, MSBFIRST, seq1[x]); //Send the data byte 1
shiftOut(dataPin, clockPin, MSBFIRST, seq2[x]); //Send the data byte 2
digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
delay(75);
}
}
void do_Clear_All()
{
bitSet(leds, 0);
digitalWrite(dataPin, 0);
digitalWrite(clockPin, 0);
delay(1000);
}
</>