Arduino Code Examples

//this is a 24 bit shift register routine for the led labs led propagatiom fountain. download this code to atmega328p on ledlabs and connect pins 9,10,11 to input of shift registers
//and it cyles through various displays.

//The latch pin is the same as the ce (chip enable)pin on shift registers//

//If any trouble compiling this code omit this and the above lines, and copy and paste everything below into arduino environment.

int dataPin = 9; //Define which pins will be used for the Shift Register control
int latchPin = 10;
int clockPin = 11;
int counter = 0;

int seq1[14] = {1,2,4,8,16,32,64,128,64,32,16,8,4,2}; //The array for storing the // byte #1 value
int seq2[14] = {128,64,32,16,8,4,2,1,2,4,8,16,32,64}; //The array for storing the // byte #2 value

int seq3[17] = {1,2,4,8,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65535};
int seq4[14] = {128,64,32,16,8,4,2,1,2,4,8,16,32,64}; //

int seq5[17] = {3,12,48,142,16,32,64,128,256,512,1024,2048,4096,8192,16384,32768,65535}; //The array for storing the// byte #1 value
int seq6[14] = {3,12,48,142,8,4,2,1,2,4,8,16,32,64}; //The array for storing the
// byte #2 value

int seq7[8] = {1,2,4,8,16,32,64,128}; //The array for storing the // byte #1 value
int seq8[8] = {128,64,32,16,8,4,2,1}; //The array for storing the // byte #2 value

int seq9[8] = {1,2,4,8,16,32,64,128}; //The array for storing the // byte #1 value
int seq10[8] = {1,2,4,8,16,32,64,128}; //The array for storing the // byte #1 value
int seq11[8] = {128,64,32,16,8,4,2,1}; //The array for storing the // byte #2 value
int seq12[8] = {128,64,32,16,8,4,2,1}; //The array for storing the // byte #2 value
int seq13[8] = {128,64,32,16,8,4,2,1}; //The array for storing the // byte #2 value
int seq14[8] = {128,64,32,16,8,4,2,1}; //The array for storing the // byte #2 value
int seq15[8] = {128,64,32,16,8,4,2,1}; //The array for storing the // byte #2 value

void setup()
{
pinMode(dataPin, OUTPUT); //Configure each IO Pin
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
}

void loop()
{
for (counter = 0; counter <10; counter++)
{

for (int x = 0; x < 14; 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(65);
}

}

for (counter = 0; counter <10; counter++)
{
for (int x = 0; x < 11; x++) //Array Index
{
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data
shiftOut(dataPin, clockPin, MSBFIRST, seq3[x]); //Send the data byte 1
shiftOut(dataPin, clockPin, MSBFIRST, seq4[x]); //Send the data byte 2
digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
delay(70);
}
}

for (counter = 0; counter <10; counter++)
{
for (int x = 0; x < 14; x++) //Array Index
{
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data
shiftOut(dataPin, clockPin, MSBFIRST, seq5[x]); //Send the data byte 1
shiftOut(dataPin, clockPin, MSBFIRST, seq6[x]); //Send the data byte 2
digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
delay(50);
}
}

for (counter = 0; counter <10; counter++)
{
for (int x = 0; x < 8; x++) //Array Index
{
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data
shiftOut(dataPin, clockPin, MSBFIRST, seq7[x]); //Send the data byte 1
shiftOut(dataPin, clockPin, MSBFIRST, seq8[x]); //Send the data byte 2
digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
delay(50);
}
}

for (counter = 0; counter <10; counter++)
{
for (int x = 0; x < 8; x++) //Array Index
{
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data
shiftOut(dataPin, clockPin, MSBFIRST, seq9[x]); //Send the data byte 1

digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
delay(50);
}
}

for (counter = 0; counter <10; counter++)
{
for (int x = 0; x < 8; x++) //Array Index
{
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data
shiftOut(dataPin, clockPin, MSBFIRST, seq10[x]); //Send the data byte 1

digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
delay(25);
}
}

for (counter = 0; counter <10; counter++)
{
for (int x = 0; x < 8; x++) //Array Index
{
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data

shiftOut(dataPin, clockPin, MSBFIRST, seq11[x]); //Send the data byte 2
digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
delay(25);
}
}

for (counter = 0; counter <10; counter++)
{
for (int x = 0; x < 8; x++) //Array Index
{
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data

shiftOut(dataPin, clockPin, MSBFIRST, seq12[x]); //Send the data byte 2
digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
delay(50);
}
}

for (counter = 0; counter <10; counter++)
{
for (int x = 0; x < 8; x++) //Array Index
{
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data

shiftOut(dataPin, clockPin, MSBFIRST, seq13[x]); //Send the data byte 2
digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
delay(75);
}
}

for (counter = 0; counter <10; counter++)
{
for (int x = 0; x < 8; x++) //Array Index
{
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data

shiftOut(dataPin, clockPin, MSBFIRST, seq14[x]); //Send the data byte 2
digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
delay(90);
}
}

for (counter = 0; counter <1; counter++)
{
for (int x = 0; x < 8; x++) //Array Index
{
digitalWrite(latchPin, LOW); //Pull latch LOW to start sending data

shiftOut(dataPin, clockPin, MSBFIRST, seq15[x]); //Send the data byte 2
digitalWrite(latchPin, HIGH); //Pull latch HIGH to stop sending data
delay(500);
}
}

}