Hello All,
I'm running into some issues with dynamic memory and am looking for some tips on bringing the coding down in size.
Currently I'm using several large arrays (160 in each). I'd imagine there's a better way to write it to bring the size down somewhat.
The context: I'm finalizing a project with 160 PC fans which turn ON and OFF. Each fan is accompanied with a plastic bag which inflates and deflates. There are laid out in somewhat of a matrix and depending on the array called up the pattern changes. Almost like a physical and analog version of a LED matrix. The fans are controlled through 74595 chips across 5x 32 Channel Mosfet boards courtesy of CrossRoads...32 MOSFET board for high currents - Exhibition / Gallery - Arduino Forum
Below is a version of the code I have going. I'd like to add several more patterns yet. Maybe hex is an option? SPI... although I'm not familiar with that? Thanks!
int latchPin = 12; //is SS
int clockPin = 13; //is CLK
int dataPin = 11; //is DI (DO)
int bitVal = 0;
int patternOFF[] = {
0,0,0,0,0,0,0,0, //1-8
0,0,0,0,0,0,0,0, //9-16
0,0,0,0,0,0,0,0, //17-24
0,0,0,0,0,0,0,0, //25-32
0,0,0,0,0,0,0,0, //33-40
0,0,0,0,0,0,0,0, //41-48
0,0,0,0,0,0,0,0, //49-56
0,0,0,0,0,0,0,0, //57-64
0,0,0,0,0,0,0,0, //65-72
0,0,0,0,0,0,0,0, //73-80
0,0,0,0,0,0,0,0, //81-88
0,0,0,0,0,0,0,0, //82-96
0,0,0,0,0,0,0,0, //97-104
0,0,0,0,0,0,0,0, //105-112
0,0,0,0,0,0,0,0, //113-120
0,0,0,0,0,0,0,0, //121-128
0,0,0,0,0,0,0,0, //129-136
0,0,0,0,0,0,0,0, //137-144
0,0,0,0,0,0,0,0, //145-152
0,0,0,0,0,0,0,0 //153-160
};
int patternTest1[] = {
0,0,0,0,0,0,0,0, //1-8
0,0,0,0,0,0,0,0, //9-16
0,0,0,0,0,0,0,0, //17-24
0,0,0,0,0,0,0,0, //25-32
0,0,0,1,1,0,0,0, //33-40
0,0,1,0,0,1,0,0, //41-48
0,1,0,0,0,1,0,0, //49-56
1,0,0,0,0,0,1,0, //57-64
0,1,0,0,0,0,0,1, //65-72
0,0,0,0,0,0,1,0, //73-80
0,0,0,0,0,1,0,0, //81-88
0,0,0,0,1,0,0,0, //82-96
0,0,0,1,0,0,0,0, //97-104
0,0,0,1,0,0,0,0, //105-112
0,0,0,1,0,0,0,0, //113-120
0,0,0,1,1,1,1,1, //121-128
0,0,0,0,0,1,0,0, //129-136
0,0,0,0,0,1,0,0, //137-144
0,0,0,0,0,1,0,0, //145-152
1,0,0,0,0,1,0,0 //153-160
};
int patternTest2[] = {
0,0,0,0,0,0,0,0, //1-8
0,0,0,0,0,1,0,0, //9-16
0,0,0,0,0,0,0,0, //17-24
0,0,0,0,0,0,0,0, //25-32
0,0,0,0,0,0,0,0, //33-40
0,0,0,0,0,0,0,0, //41-48
1,1,1,1,1,1,1,1, //49-56
0,0,0,0,0,0,0,0, //57-64
0,0,0,0,0,0,0,0, //65-72
0,0,0,0,0,0,0,0, //73-80
1,1,1,1,1,1,1,1, //81-88
0,0,0,0,0,0,0,0, //82-96
0,0,0,0,0,0,0,0, //97-104
0,0,0,0,0,0,0,0, //105-112
0,0,0,0,0,0,0,0, //113-120
0,0,0,0,0,0,1,0, //121-128
0,0,0,0,0,0,0,0, //129-136
0,0,0,0,0,0,0,0, //137-144
0,0,0,0,0,0,0,0, //145-152
0,0,0,0,0,0,0,0 //153-160
};
int patternTest3[] = {
0,1,0,0,0,1,0,0, //1-8
0,1,0,0,0,1,0,0, //9-16
0,1,0,0,0,1,0,0, //17-24
0,1,0,0,0,1,0,0, //25-32
0,1,0,0,0,1,0,0, //33-40
0,1,0,0,0,1,0,0, //41-48
0,1,0,0,0,1,0,0, //49-56
0,1,0,0,0,1,0,0, //57-64
0,1,0,0,0,1,0,0, //65-72
0,1,0,0,0,1,0,0, //73-80
0,1,0,0,0,1,0,0, //81-88
0,0,1,0,0,1,0,0, //82-96
0,0,0,1,0,1,0,0, //97-104
0,0,0,0,1,1,0,0, //105-112
0,0,0,0,0,1,0,0, //113-120
0,0,0,0,0,1,1,0, //121-128
0,0,0,0,0,1,0,0, //129-136
0,0,0,0,0,1,0,0, //137-144
0,0,0,0,0,1,0,0, //145-152
0,0,0,0,0,1,0,0 //153-160
};
int patternTest4[] = {
0,0,0,0,0,0,0,0, //1-8
0,0,0,0,0,1,0,0, //9-16
0,0,0,0,0,0,0,0, //17-24
0,0,0,0,0,0,0,0, //25-32
0,0,0,0,0,0,0,0, //33-40
0,0,0,0,0,0,0,0, //41-48
0,0,0,0,0,0,0,0, //49-56
0,0,0,0,0,0,0,0, //57-64
0,1,0,0,0,0,0,0, //65-72
0,0,0,0,0,0,0,0, //73-80
0,0,0,0,0,0,0,0, //81-88
0,0,0,0,0,0,0,0, //82-96
0,0,0,0,0,0,0,0, //97-104
0,0,0,0,0,0,0,0, //105-112
0,0,0,0,0,0,0,0, //113-120
0,0,0,0,0,0,0,0, //121-128
0,0,0,0,0,0,0,0, //129-136
0,0,0,0,0,0,0,0, //137-144
0,0,0,0,0,0,0,0, //145-152
0,0,0,0,0,0,0,0 //153-160
};
void setup() {
Serial.begin(9600);
pinMode(latchPin, OUTPUT);
pinMode(clockPin, OUTPUT);
pinMode(dataPin, OUTPUT);
}
void loop() {
runPatternOFF();
delay(15000);
runPatternTest1();
delay(15000);
runPatternTest2();
delay(15000);
runPatternTest3();
delay(12000);
runPatternTest4();
delay(15000);
}
void runPatternOFF(){
digitalWrite(latchPin, LOW); //ground latchPin and hold low for as long as you are transmitting
for (int i = 160; i >= 0; i--){
bitVal = patternOFF[i];
Serial.print(bitVal);
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, bitVal);
digitalWrite(clockPin, HIGH);
}
Serial.println(" = PatternOFF");
digitalWrite(latchPin, HIGH); //return the latch pin high to signal chip that it
}
void runPatternTest1(){
digitalWrite(latchPin, LOW); //ground latchPin and hold low for as long as you are transmitting
for (int i = 160; i >= 0; i--){
bitVal = patternTest1[i];
Serial.print(bitVal);
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, bitVal);
digitalWrite(clockPin, HIGH);
}
Serial.println(" = PatternTest1");
digitalWrite(latchPin, HIGH); //return the latch pin high to signal chip that it
}
void runPatternTest2(){
digitalWrite(latchPin, LOW); //ground latchPin and hold low for as long as you are transmitting
for (int i = 160; i >= 0; i--){
bitVal = patternTest2[i];
Serial.print(bitVal);
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, bitVal);
digitalWrite(clockPin, HIGH);
}
Serial.println(" = PatternTest2");
digitalWrite(latchPin, HIGH); //return the latch pin high to signal chip that it
}
void runPatternTest3(){
digitalWrite(latchPin, LOW); //ground latchPin and hold low for as long as you are transmitting
for (int i = 160; i >= 0; i--){
bitVal = patternTest3[i];
Serial.print(bitVal);
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, bitVal);
digitalWrite(clockPin, HIGH);
}
Serial.println(" = PatternTest3");
digitalWrite(latchPin, HIGH); //return the latch pin high to signal chip that it
}
void runPatternTest4(){
digitalWrite(latchPin, LOW); //ground latchPin and hold low for as long as you are transmitting
for (int i = 160; i >= 0; i--){
bitVal = patternTest4[i];
Serial.print(bitVal);
digitalWrite(clockPin, LOW);
digitalWrite(dataPin, bitVal);
digitalWrite(clockPin, HIGH);
}
Serial.println(" = PatternTest4");
digitalWrite(latchPin, HIGH); //return the latch pin high to signal chip that it
}