Данный ниже cкетч работает так, как было задумано, но работает через раз. Еcть подозрение, что где-то утекает память, но ошибку cамоcтоятельно отловить не удаетcя.
int DIN = 12;
int CS = 11;
int CLK = 10;
int strlength; // length of the string recieved from serial
bool gotText = false; //flag of "string was recieved"
LedControl lc=LedControl(DIN,CLK,CS,0);
using namespace std;
byte sprites[][8] = // letter sprites for 8*8 matrix
{
{B00000000,B00011000,B00100100,B00100100,B00111100,B00100100,B00100100,B00000000},
{B00000000,B00111000,B00100100,B00111000,B00100100,B00100100,B00111000,B00000000},
{B00000000,B00111100,B00100000,B00100000,B00100000,B00100000,B00111100,B00000000},
{B00000000,B00111000,B00100100,B00100100,B00100100,B00100100,B00111000,B00000000},
{B00000000,B00111100,B00100000,B00111100,B00100000,B00100000,B00111100,B00000000},
{B00000000,B00111100,B00100000,B00111100,B00100000,B00100000,B00100000,B00000000},
{B00000000,B00111100,B00100000,B00100000,B00101100,B00100100,B00111100,B00000000},
{B00000000,B00100100,B00100100,B00100100,B00111100,B00100100,B00100100,B00000000},
{B00000000,B00111100,B00011000,B00011000,B00011000,B00011000,B00111100,B00000000},
{B00000000,B00111100,B00010000,B00010000,B00010000,B00010100,B00001000,B00000000},
{B00000000,B00100100,B00101000,B00110000,B00101000,B00100100,B00100100,B00000000},
{B00000000,B00100000,B00100000,B00100000,B00100000,B00100100,B00111100,B00000000},
{B00000000,B00100000,B00100000,B00100000,B00100000,B00100100,B00111100,B00000000},
{B00000000,B00100000,B00100000,B00100000,B00100000,B00100100,B00111100,B00000000},
{B00000000,B00100000,B00100000,B00100000,B00100000,B00100100,B00111100,B00000000},
{B00000000,B00100000,B00100000,B00100000,B00100000,B00100100,B00111100,B00000000},
{B00000000,B00100000,B00100000,B00100000,B00100000,B00100100,B00111100,B00000000},
{B00000000,B00111000,B00100100,B00111000,B00110000,B00101000,B00100100,B00000000},
{B00000000,B00011100,B00100000,B00100000,B00011000,B00000100,B00111000,B00000000},
{B00000000,B01111110,B00011000,B00011000,B00011000,B00011000,B00011000,B00000000},
{B00000000,B00100100,B00100100,B00100100,B00100100,B00100100,B00011000,B00000000},
{B00000000,B00100100,B00100100,B00100100,B00100100,B00100100,B00011000,B00000000},
{B00000000,B01011010,B01011010,B01011010,B01011010,B01011010,B00100100,B00000000},
{B00000000,B00100100,B00100100,B00011000,B00011000,B00100100,B00100100,B00000000},
{B00000000,B00100100,B00100100,B00011000,B00001000,B00001000,B00110000,B00000000},
{B00000000,B00111100,B00000100,B00001000,B00010000,B00100000,B00111100,B00000000}
};
void printByte(byte character [], byte character1 []) // prints two consecutive bytes
{
for (int i=0;i<9;i++)
{
int t = 1;
for (int j=0; j<9-i;j++)
{
lc.setRow(0, j, character[i+j]);
}
for (int k=9-i; k<9;k++)
{
lc.setRow(0, k, character1[t]);
t++;
}
delay(150);
}
}
int *SerialInput() // recieves string from input and generates array of ascii values
{
if (Serial.available()>0)
{
String input;
static int s_asciiStr[100];
input = Serial.readString()
strlength = input.length() - 1;
for (int i = 0;i < input.length(); i++)
s_asciiStr[i] = int(input[i]);
gotText = true;
return s_asciiStr;
}
}
void setup()
{
Serial.begin(9600);
lc.shutdown(0,false);
lc.setIntensity(0,15);
lc.clearDisplay(0);
}
void loop() // shows sprites according to pre generated array of ascii values
{
SerialInput();
if(gotText == true)
{
int *p;
p=SerialInput();
for (int i = 0;i < strlength - 1;i++)
printByte(sprites[*(p+i)-65],sprites[*(p+i+1) - 65]);
gotText = false;
}
}