Here's my full code.
In this example, I send the byte from the array running[]. (which the data has been modified to byte form . e.g : B00000011, B00000001 .....
My main question is, how can I send the data to shift register using only raw array data. So that I don't have to modify every 8 bits and put 'B' character manually, and put comma at the end.
//Pin connected to ST_CP of 74HC595
int latchPin = 8;
//Pin connected to SH_CP of 74HC595
int clockPin = 12;
////Pin connected to DS of 74HC595
int dataPin = 11;
//holders for information you're going to pass to shifting function
byte module1;
byte module2;
byte newval;
int delaytime= 20;
byte running[]={
/* raw array
11111000,00000000,
11111110,00000000,
11111111,10000000,
11111111,11000000,
11111111,11100000,
11111111,11110000,
11111111,11111000,
11111111,11111000,
11111111,11111000,
11111111,11111100,
11111111,11111100,
11111111,11111100,
11111111,11111100,
11111111,11111100,
11111111,11111100,
11111111,11111100,
11111111,11111100,
11111111,11111100,
11111111,11111000,
11111111,11111000,
11111111,11110000,
11111111,11100000,
11111111,11100000,
11111111,10000000,
11111111,00000000,
11111100,00000000,
11100000,00000011,
00000000,00001111,
00000000,00111111,
00000000,01111111,
00000000,11111111,
00000001,11111111,
00000001,11111111,
00000011,11111111,
00000011,11111111,
00000111,11111111,
00000111,11111111,
00000111,11111111,
00000111,11111111,
00000111,11111111,
00000111,11111111,
00000111,11111111,
00000111,11111111,
00000111,11111111,
00000011,11111111,
00000011,11111111,
00000001,11111111,
00000000,11111111,
00000000,01111111,
00000000,00111111,
00000000,00011111,
00000000,00000111,
*/
B11111000,B00000000,
B11111110,B00000000,
B11111111,B10000000,
B11111111,B11000000,
B11111111,B11100000,
B11111111,B11110000,
B11111111,B11111000,
B11111111,B11111000,
B11111111,B11111000,
B11111111,B11111100,
B11111111,B11111100,
B11111111,B11111100,
B11111111,B11111100,
B11111111,B11111100,
B11111111,B11111100,
B11111111,B11111100,
B11111111,B11111100,
B11111111,B11111100,
B11111111,B11111000,
B11111111,B11111000,
B11111111,B11110000,
B11111111,B11100000,
B11111111,B11100000,
B11111111,B10000000,
B11111111,B00000000,
B11111100,B00000000,
B11100000,B00000011,
B00000000,B00001111,
B00000000,B00111111,
B00000000,B01111111,
B00000000,B11111111,
B00000001,B11111111,
B00000001,B11111111,
B00000011,B11111111,
B00000011,B11111111,
B00000111,B11111111,
B00000111,B11111111,
B00000111,B11111111,
B00000111,B11111111,
B00000111,B11111111,
B00000111,B11111111,
B00000111,B11111111,
B00000111,B11111111,
B00000111,B11111111,
B00000011,B11111111,
B00000011,B11111111,
B00000001,B11111111,
B00000000,B11111111,
B00000000,B01111111,
B00000000,B00111111,
B00000000,B00011111,
B00000000,B00000111,
};
int codesize = sizeof(running)/ sizeof(int);
int lines= codesize; //54 numbers of coding lines
int nooflines = (lines*2)-1;
int noofmodules = 2; // numbers of module connected
// stringThree = stringOne + 'A';
void setup() {
//set pins to output because they are addressed in the main loop
pinMode(latchPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
for (int j = 0; j <= nooflines; j=j+noofmodules) {
//load the light sequence you want from array
module1 = running[j];
module2 = running[j+1];
//stringThree = stringOne + 'A';
//ground latchPin and hold low for as long as you are transmitting
digitalWrite(latchPin, 0);
//move 'em out
shiftOut(dataPin, clockPin, module2);
shiftOut(dataPin, clockPin, module1);
//return the latch pin high to signal chip that it
//no longer needs to listen for information
digitalWrite(latchPin, 1);
delay(delaytime);
}
}
// the heart of the program
void shiftOut(int myDataPin, int myClockPin, byte myDataOut) {
// This shifts 8 bits out MSB first,
//on the rising edge of the clock,
//clock idles low
//internal function setup
int i=0;
int pinState;
pinMode(myClockPin, OUTPUT);
pinMode(myDataPin, OUTPUT);
//clear everything out just in case to
//prepare shift register for bit shifting
digitalWrite(myDataPin, 0);
digitalWrite(myClockPin, 0);
//for each bit in the byte myDataOut[ch65533]
//NOTICE THAT WE ARE COUNTING DOWN in our for loop
//This means that %00000001 or "1" will go through such
//that it will be pin Q0 that lights.
for (i=0; i<=7; i++) {
digitalWrite(myClockPin, 0);
//if the value passed to myDataOut and a bitmask result
// true then... so if we are at i=6 and our value is
// %11010100 it would the code compares it to %01000000
// and proceeds to set pinState to 1.
if ( myDataOut & (1<<i) ) {
pinState= 1;
}
else {
pinState= 0;
}
//Sets the pin to HIGH or LOW depending on pinState
digitalWrite(myDataPin, pinState);
//register shifts bits on upstroke of clock pin
digitalWrite(myClockPin, 1);
//zero the data pin after shift to prevent bleed through
digitalWrite(myDataPin, 0);
}
//stop shifting
digitalWrite(myClockPin, 0);
}
thank you.