#include "storage.h"
// *Note: Don't use PROGMEM, because it'll make the code not get the proper values!!!
int lsindex = 0; // index of read letter in template
int pixpos = 0;
long steppos = 0;
byte letter = 0;
byte pixval = 0;
byte cmsht = 29;
byte pmsht = 59;
byte stcpx = 27;
byte stppx = 61;
byte pxln = 9;
long lnfsa = 0;
byte printmode = 0; // defaults to text
byte pxpos = 0;
byte iscommand = 0;
void setup() {
DDRB = 255;
PORTB = 0;
pinMode(6, INPUT_PULLUP); // koncový kalibračný spínač (limit switch for homing)
pinMode(A1, INPUT_PULLUP); // posuv papiera von (move paper out of the output(blank line feed))
pinMode(A2, INPUT_PULLUP); // posuv papiera dnu (move paper into the output(blank line unfeed))
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(19200);
digitalWrite(3, LOW);
while (digitalRead(6) == HIGH) {
digitalWrite(2, HIGH);
delayMicroseconds(125);
digitalWrite(2, LOW);
delayMicroseconds(125);
}
digitalWrite(3, HIGH);
for (int s = 0; s < (stcpx * 26); s = s + 1) {
digitalWrite(2, HIGH);
delayMicroseconds(125);
digitalWrite(2, LOW);
delayMicroseconds(125);
}
delay(250);
Serial.write(0x0A); // tento riadok môžete vynechať
}
void loop() {
if (digitalRead(A1) == LOW) {
delay(500);
bplf();
}
if (digitalRead(A2) == LOW) {
delay(500);
bpluf();
}
while (Serial.available()) {
if (pixpos >= 120) {
pixpos = 0;
pxpos = 0;
crlf();
}
if (pxpos >= 120) {
pixpos = 0;
pxpos = 0;
crlf();
}
if (Serial.available() >= 20) {
Serial.write(0x13);
}
if (Serial.available() <= 3) {
Serial.write(0x11);
}
letter = Serial.read();
if (letter == 27) {
iscommand = 1;
continue;
}
else if (iscommand == 1) {
if (letter == 'E') {
for (byte w = 0; w < 50; w = w + 1) {
pxln = 10;
bpluf;
}
}
else if (letter == 'G') {
printmode = 1;
crlf();
}
else if (letter == 'L') {
pxln = 4;
for (byte u = 0; u < 9; u = u + 1) {
bplf();
}
pxln = 10;
}
else if (letter == 'T') {
printmode = 0;
crlf();
}
else {
continue;
}
iscommand = 0;
}
else if (letter <= 31 && letter != 27) {
return;
}
else {
if (printmode == 1) {
dotmatrixgraphics(letter);
}
if (printmode == 0) {
dotmatrixtext(letter);
}
}
}
}
void dotmatrixgraphics(byte graphdat) {
pxln = 7;
digitalWrite(3, HIGH);
pxpos = pxpos + 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 = graphdat;
}
}
}
void dotmatrixtext(byte character) {
pxln = 10;
digitalWrite(3, HIGH);
lsindex = (character - 32) * 6;
for (byte i = 0; i < 6; i = i + 1) {
pixval = 0;
pixval = font[lsindex + i];
pixpos = pixpos + 1;
pxpos = pxpos + 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() {
lnfsa = pxln * stppx;
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);
}
}
Homing switch
Line feed
Carriage move
Paper feed out of printer
Paper feed into printer