// current image is testarr. Replace with image data of your choosing. Image must be one byte per pixel, where black pixel is 1 and white pixel is 0.
#include "ulozisko.h"
void setup() {
pinMode(2, INPUT_PULLUP); // line
pinMode(3, INPUT_PULLUP); // collumn
pinMode(4, OUTPUT); // leftmost needle
pinMode(5, OUTPUT);
pinMode(6, OUTPUT);
pinMode(7, OUTPUT);
pinMode(8, OUTPUT);
pinMode(9, OUTPUT);
pinMode(10, OUTPUT);
pinMode(11, OUTPUT); // rightmost needle
pinMode(12, OUTPUT); // motor pin
attachInterrupt(digitalPinToInterrupt(2), skuska, RISING); // don't forget to change RISING to FALLING
attachInterrupt(digitalPinToInterrupt(3), skuska2, CHANGE);
Serial.begin(9600);
Serial.println(" ");
line = 0;
}
void skuska() {
if (ready == 1) {
line = line + 1;
}
if (ready == 0) {
ready = 1;
}
count = 0;
bod = 0;
dot = 0;
if (line > 7) {
row = row + 1;
line = 0;
}
if (row >= 12) {
row = 0;
line = 0;
}
}
void skuska2() {
if (count < maxcount && ready == 1) {
count = count + 1;
} else if (ready == 0) {
count = 0;
}
else if (count >= maxcount) {
count = maxcount;
}
}
void loop() {
while (toprint == 0) {
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
digitalWrite(12, LOW);
line, dot, bod, count, row = 0;
if (Serial.available()) {
receive = Serial.readStringUntil(10);
Serial.read();
/*if(receive == "Hello!") {
textprint("Hi! How are you?");
} else if (receive == "I am fine. How about you?") { // primitive ChatGPT 0.00001 source code
textprint("I am also fine, but could be better.");
} else if(receive == "What is wrong?") {
textprint("I am a printer trapped in a box.");
}
else {*/
textprint(receive);
/*
}*/
}
}
}
void stringprocess(String proces) { // processes the string into 240px wide, 8px tall lines
int lsindex = 0; // index of where letter starts in font array (0x20 to 0xfe only, so no Unicode chars)
byte printarea[240] = {0};
for (byte i = 0; i < 240; i = i + 1) {
printarea[i] = 0;
}
for (byte w = 0; w < proces.length(); w = w + 1) {
letter = proces[w];
byte intermid = letter - 32;
lsindex = intermid * 6;
for (byte i = 0; i < 6; i = i + 1) {
collumn = 0;
uint32_t address = &font[lsindex + i];
collumn = pgm_read_byte(address);
printarea[i + (6 * w)] = collumn;
}
}
toprint = 1;
doprint(printarea);
}
void stringsplit(String received) {
String process = "";
if (received.length() > 40) {
for (int r = 0; r < received.length(); r = r + 40) {
process = "";
for (byte e = 0; e < 40; e = e + 1) {
char toputtoarr = received[(r + e)];
if (toputtoarr == 0) {
break;
} else {
process += toputtoarr;
}
}
stringprocess(process);
process = "";
}
} else {
process = received;
stringprocess(process);
}
received = "";
}
void textprint(String text) {
stringsplit(text);
}
void m192print(byte value) {
String text = String(value);
textprint(text);
}
void m192print(int value) {
String text = String(value);
textprint(text);
}
void m192print(unsigned int value) {
String text = String(value);
textprint(text);
}
void m192print(long value) {
String text = String(value);
textprint(text);
}
void m192print(unsigned long value) {
String text = String(value);
textprint(text);
}
void doprint(byte arr1[240]) {
while (toprint == 1) {
digitalWrite(12, HIGH);
bod = count / 3.00;
dot = count / 3;
if (dot >= 30) {
dot = 29;
}
totoff2 = dot + bodoff2;
totoff3 = dot + bodoff3;
totoff4 = dot + bodoff4;
totoff5 = dot + bodoff5;
totoff6 = dot + bodoff6;
totoff7 = dot + bodoff7;
totoff8 = dot + bodoff8;
truoff1 = dot + (240 * row);
truoff2 = totoff2 + (240 * row);
truoff3 = totoff3 + (240 * row);
truoff4 = totoff4 + (240 * row);
truoff5 = totoff5 + (240 * row);
truoff6 = totoff6 + (240 * row);
truoff7 = totoff7 + (240 * row);
truoff8 = totoff8 + (240 * row);
val = ((((arr1[truoff1]) >> line) & 1) + (2 * (((arr1[truoff2]) >> line) & 1)) + (4 * (((arr1[truoff3]) >> line) & 1)) + (8 * (((arr1[truoff4]) >> line) & 1)) + (16 * (((arr1[truoff5]) >> line) & 1)) + (32 * (((arr1[truoff6]) >> line) & 1)) + (64 * (((arr1[truoff7]) >> line) & 1)) + (128 * (((arr1[truoff8]) >> line) & 1)));
if (ready == 0) {
val = 0;
}
if (bod - dot < 0.2 || ready == 1) { // don't forget to change || to &&
digitalWrite(4, (val & 1));
digitalWrite(5, (val & 2));
digitalWrite(6, (val & 4));
digitalWrite(7, (val & 8));
digitalWrite(8, (val & 16));
digitalWrite(9, (val & 32));
digitalWrite(10, (val & 64));
digitalWrite(11, (val & 128));
} else {
digitalWrite(4, LOW);
digitalWrite(5, LOW);
digitalWrite(6, LOW);
digitalWrite(7, LOW);
digitalWrite(8, LOW);
digitalWrite(9, LOW);
digitalWrite(10, LOW);
digitalWrite(11, LOW);
}
if (row) {
val = 0;
ready = 0;
line = 0;
row = 0;
toprint = 0;
for (byte i = 0; i < 240; i = i + 1) {
arr1[i] = 0;
}
}
} // label just for the hell of it
}