Isn't this confusing? All these "a" variables?
byte a[8];
...
void writeArduinoOnMatrix1() {
/* here is the data for the characters */
static byte a[8]={
B00111100,B01111110,B11100111,B11001011,B11010011,B11100111,B01111110,B00111100, };
...
displayThem(a);
}
void writeArduinoOnMatrix2() {
static byte a[8]={
B11111111,B11111110,B11100000,B11010000,B11001000,B11000100,B11000010,B10000001, };
...
displayThem(a);
}
void writeArduinoOnMatrix3() {
static byte a[8]={
B11111111,B01111111,B00000111,B00001011,B00010011,B00100011,B01000011,B10000001 };
...
displayThem(a);
}
void writeArduinoOnMatrix4() {
// here is the data for the characters
static byte a[8]={
B00011000,B00111000,B00111000,B00011000,B00011000,B00011000,B00111100,B00111100 };
...
displayThem(a);
}
Instead of trying to call these different functions, why not just display the correct pattern from an array? Like this:
// 4 lots of 8
const byte bitPatterns [4] [8] =
{
{ B00111100,B01111110,B11100111,B11001011,B11010011,B11100111,B01111110,B00111100, } , // matrix 1
{ B11111111,B11111110,B11100000,B11010000,B11001000,B11000100,B11000010,B10000001, } , // matrix 2
{ B11111111,B01111111,B00000111,B00001011,B00010011,B00100011,B01000011,B10000001, } , // matrix 3
{ B00011000,B00111000,B00111000,B00011000,B00011000,B00011000,B00111100,B00111100, } , // matrix 4
}; // end of bitPatterns
And display like this:
if (hex >= 1 && hex <= 4)
displayThem (bitPatterns [hex - 1]);
else
lc.clearDisplay(0);
And make the display function simpler:
void displayThem(const byte a[8])
{
for (byte i = 0; i < 8; i++)
lc.setRow(0,i,a[i]);
} // end of displayThem
Now the problem of calling lots of different functions quietly goes away. Finished code (not tested):
//We always have to include the library
#include "LedControl.h"
/*
Now we need a LedControl to work with.
***** These pin numbers will probably not work with your hardware *****
pin 12 is connected to the DataIn
pin 11 is connected to the CLK
pin 10 is connected to LOAD
We have only a single MAX72XX.
*/
LedControl lc=LedControl(12,11,10,1);
int pin1 = 2;
int pin3 = 3;
int pin4 = 4;
int pin6 = 5;
//pins with 0 on the left
// 4 5 6
//
// 1 2 3
//connect vcc to pins 2 and 5
int input1 = 0;
int input2 = 0;
int input3 = 0;
int input4 = 0;
int hex;
// 4 lots of 8
const byte bitPatterns [4] [8] =
{
{ B00111100,B01111110,B11100111,B11001011,B11010011,B11100111,B01111110,B00111100, } , // matrix 1
{ B11111111,B11111110,B11100000,B11010000,B11001000,B11000100,B11000010,B10000001, } , // matrix 2
{ B11111111,B01111111,B00000111,B00001011,B00010011,B00100011,B01000011,B10000001, } , // matrix 3
{ B00011000,B00111000,B00111000,B00011000,B00011000,B00011000,B00111100,B00111100, } , // matrix 4
}; // end of bitPatterns
/* we always wait a bit between updates of the display */
unsigned long delaytime=10;
void setup() {
Serial.begin(9600);
pinMode(pin1, INPUT);
pinMode(pin3, INPUT);
pinMode(pin4, INPUT);
pinMode(pin6, INPUT);
/*
The MAX72XX is in power-saving mode on startup,
we have to do a wakeup call
*/
lc.shutdown(0,false);
/* Set the brightness to a medium values */
lc.setIntensity(0,1);
/* and clear the display */
lc.clearDisplay(0);
}
void displayThem(const byte a[8])
{
for (byte i = 0; i < 8; i++)
lc.setRow(0,i,a[i]);
} // end of displayThem
void loop()
{
Serial.println (hex);
input1 = digitalRead(pin1);
input2 = digitalRead(pin3);
input3 = digitalRead(pin4);
input4 = digitalRead(pin6);
if (input1 == 0)
{
bitWrite (hex,0,1);
}
else
{
bitWrite (hex,0,0);
}
if (input4 == 0)
{
bitWrite (hex,1,1);
}
else
{
bitWrite (hex,1,0);
}
if (input2 == 0)
{
bitWrite (hex,2,1);
}
else
{
bitWrite (hex,2,0);
}
if (input3 == 0)
{
bitWrite (hex,3,1);
}
else
{
bitWrite (hex,3,0);
}
if (hex >= 1 && hex <= 4)
displayThem (bitPatterns [hex - 1]);
else
lc.clearDisplay(0);
}
I have no idea what this is doing, BTW:
input1 = digitalRead(pin1);
input2 = digitalRead(pin3);
input3 = digitalRead(pin4);
input4 = digitalRead(pin6);
if (input1 == 0)
{
bitWrite (hex,0,1);
}
else
{
bitWrite (hex,0,0);
}
if (input4 == 0)
{
bitWrite (hex,1,1);
}
else
{
bitWrite (hex,1,0);
}
if (input2 == 0)
{
bitWrite (hex,2,1);
}
else
{
bitWrite (hex,2,0);
}
if (input3 == 0)
{
bitWrite (hex,3,1);
}
else
{
bitWrite (hex,3,0);
}