// 0x20 to 0x7f ascii
unsigned char font[571] = {
0, 0, 0, 0, 0, 0, 0, 0, 95, 0, 0, 0, 0, 7, 0, 7,
0, 0, 20, 127, 20, 127, 20, 0, 36, 42, 127, 42, 18, 0, 35, 19,
8, 100, 98, 0, 54, 73, 85, 34, 80, 0, 0, 0, 7, 0, 0, 0,
0, 28, 34, 65, 0, 0, 0, 65, 34, 28, 0, 0, 20, 8, 62, 8,
20, 0, 8, 8, 62, 8, 8, 0, 0, 80, 48, 0, 0, 0, 8, 8,
8, 8, 8, 0, 0, 96, 96, 0, 0, 0, 32, 16, 8, 4, 2, 0,
62, 81, 73, 69, 62, 0, 0, 66, 127, 64, 0, 0, 66, 97, 81, 73,
70, 0, 34, 65, 73, 73, 54, 0, 24, 20, 18, 127, 16, 0, 39, 69,
69, 69, 57, 0, 60, 74, 73, 73, 48, 0, 1, 1, 113, 9, 7, 0,
54, 73, 73, 73, 54, 0, 6, 73, 73, 41, 30, 0, 0, 54, 54, 0,
0, 0, 0, 86, 54, 0, 0, 0, 8, 20, 34, 65, 0, 0, 20, 20,
20, 20, 20, 0, 0, 65, 34, 20, 8, 0, 2, 1, 81, 9, 6, 0,
50, 73, 121, 65, 126, 0, 126, 9, 9, 9, 126, 0, 127, 73, 73, 73,
54, 0, 62, 65, 65, 65, 34, 0, 127, 65, 65, 34, 28, 0, 127, 73,
73, 73, 65, 0, 127, 9, 9, 9, 1, 0, 62, 65, 73, 73, 122, 0,
127, 8, 8, 8, 127, 0, 0, 65, 127, 65, 0, 0, 32, 64, 65, 63,
1, 0, 127, 8, 20, 34, 65, 0, 127, 64, 64, 64, 64, 0, 127, 2,
12, 2, 127, 0, 127, 4, 8, 16, 127, 0, 62, 65, 65, 65, 62, 0,
127, 9, 9, 9, 6, 0, 62, 65, 81, 33, 94, 0, 127, 9, 25, 41,
70, 0, 70, 73, 73, 73, 49, 0, 1, 1, 127, 1, 1, 0, 63, 64,
64, 64, 63, 0, 31, 32, 64, 32, 31, 0, 63, 64, 56, 64, 63, 0,
99, 20, 8, 20, 99, 0, 7, 8, 112, 8, 7, 0, 97, 81, 73, 69,
67, 0, 0, 127, 65, 65, 0, 0, 2, 4, 8, 16, 32, 0, 0, 65,
65, 127, 0, 0, 4, 2, 1, 2, 4, 0, 64, 64, 64, 64, 64, 0,
0, 1, 2, 4, 0, 0, 32, 84, 84, 84, 120, 0, 127, 72, 68, 68,
56, 0, 56, 68, 68, 68, 32, 0, 56, 68, 68, 72, 127, 0, 56, 84,
84, 84, 88, 0, 8, 126, 9, 1, 2, 0, 12, 82, 82, 82, 62, 0,
127, 8, 4, 4, 120, 0, 0, 68, 125, 64, 0, 0, 32, 64, 68, 61,
0, 0, 127, 16, 40, 68, 0, 0, 0, 65, 127, 64, 0, 0, 124, 4,
120, 4, 120, 0, 124, 8, 4, 4, 120, 0, 56, 68, 68, 68, 56, 0,
124, 20, 20, 20, 8, 0, 8, 20, 20, 24, 124, 0, 124, 8, 4, 4,
8, 0, 72, 84, 84, 84, 36, 0, 4, 63, 68, 64, 32, 0, 60, 64,
64, 32, 124, 0, 28, 32, 64, 32, 28, 0, 60, 64, 48, 64, 60, 0,
68, 40, 16, 40, 68, 0, 12, 80, 80, 80, 60, 0, 68, 100, 84, 76,
68, 0, 0, 8, 54, 65, 0, 0, 0, 0, 127, 0, 0, 0, 0, 65,
54, 8, 0, 0, 16, 8, 8, 16, 8, 0
};
bool prar[8][122];
int lsindex = 0; // index of read letter in template
int letpos = 0;
int pixpos = 0;
long steppos = 0;
unsigned char letter = 0;
byte pixval = 0;
String received = "";
byte cmsht = 30;
byte pmsht = 60;
byte stcpx = 27;
byte stppx = 61;
byte pxln = 9;
long lnfsa = 0;
byte fromprar = 0;
void setup() {
DDRB = 255;
pinMode(6, INPUT_PULLUP); // koncový kalibračný spínač
pinMode(A1, INPUT_PULLUP); // posuv o 5mm von
pinMode(A2, INPUT_PULLUP); // posuv o 5mm dnu
pinMode(2, OUTPUT); // stepper 1 step
pinMode(3, OUTPUT); // stepper 1 dir
pinMode(4, OUTPUT); // stepper 2 step
pinMode(5, OUTPUT); // stepper 2 dir
Serial.begin(9600);
Serial.write(0x0A); // tento riadok môžete vynechať
}
void loop() {
while (!Serial.available()) {
if (digitalRead(A1) == LOW) {
delay(500);
bplf();
}
if (digitalRead(A2) == LOW) {
delay(500);
bpluf();
}
}
received = sstringr();
for(int r = 0; r < 8; r = r + 1) {
for(int q = 0; q < 120; q = q + 1) {
Serial.print(prar[r][q]);
}
Serial.write(10);
}
for (byte f = 0; f < received.length(); f = f + 1) {
letter = received[f];
if (letter == 10 || letter == 13 || letpos > 19) {
letpos = 0;
lnfsa = pxln * stppx;
crlf();
continue;
}
else {
dotmatrix(letter);
letpos = letpos + 1;
}
}
}
void dotmatrix(unsigned char character) {
digitalWrite(3, HIGH);
lsindex = (character - 32) * 6;
for (byte i = 0; i < 6; i = i + 1) {
pixval = font[lsindex + i];
prar[0][pixpos] = (pixval & 0b00000001);
prar[1][pixpos] = (pixval & 0b00000010);
prar[2][pixpos] = (pixval & 0b00000100);
prar[3][pixpos] = (pixval & 0b00001000);
prar[4][pixpos] = (pixval & 0b00010000);
prar[5][pixpos] = (pixval & 0b00100000);
prar[6][pixpos] = (pixval & 0b01000000);
prar[7][pixpos] = (pixval & 0b10000000);
/* for (byte b = 8; b-- > 0;){
if ((pixval >> b & 0x01) == 0){
Serial.print(' ');
} else {
Serial.print('#');
}
}
Serial.println();
*/
pixpos = pixpos + 1;
for (byte y = 0; y < stcpx; y = y + 1) {
steppos = steppos + 1;
digitalWrite(2, HIGH);
delayMicroseconds(cmsht);
digitalWrite(2, LOW);
delayMicroseconds(cmsht);
if (y > 10) {
PORTB = 0;
}
else {
PORTB = pixval;
}
}
}
}
void crlf() {
digitalWrite(3, LOW);
digitalWrite(5, HIGH);
while (steppos > 0) {
steppos = steppos - 1;
digitalWrite(2, HIGH);
delayMicroseconds(cmsht);
digitalWrite(2, LOW);
delayMicroseconds(cmsht);
}
while (lnfsa > 0) {
lnfsa = lnfsa - 1;
digitalWrite(4, HIGH);
delayMicroseconds(pmsht);
digitalWrite(4, LOW);
delayMicroseconds(pmsht);
}
}
void bplf() {
digitalWrite(5, HIGH);
lnfsa = pxln * stppx;
while (lnfsa > 0) {
lnfsa = lnfsa - 1;
digitalWrite(4, HIGH);
delayMicroseconds(pmsht);
digitalWrite(4, LOW);
delayMicroseconds(pmsht);
}
}
void bpluf() {
digitalWrite(5, LOW);
lnfsa = pxln * stppx;
while (lnfsa > 0) {
lnfsa = lnfsa - 1;
digitalWrite(4, HIGH);
delayMicroseconds(pmsht);
digitalWrite(4, LOW);
delayMicroseconds(pmsht);
}
}
String sstringr() {
char message = 0;
String content = "";
while (Serial.available()) {
message = Serial.read();
content += message;
}
if (content != "") {
return content;
}
}