// current image is testimg . 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"
int line = 0;
int count = 0;
int dot = 0;
float bod = 0;
byte ready = 0;
byte maxcount = 89;
int bodoff1 = 0;
int bodoff2 = 30;
int bodoff3 = 60;
int bodoff4 = 90;
int bodoff5 = 120;
int bodoff6 = 150;
int bodoff7 = 180;
int bodoff8 = 210;
int totoff1 = 0;
int totoff2 = 0;
int totoff3 = 0;
int totoff4 = 0;
int totoff5 = 0;
int totoff6 = 0;
int totoff7 = 0;
int totoff8 = 0;
byte val = 0;
void setup() {
pinMode(2, INPUT); // line
pinMode(3, INPUT); // 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);
attachInterrupt(digitalPinToInterrupt(3), skuska2, CHANGE);
digitalWrite(12, HIGH);
delay(1000);
line = 0;
}
void skuska() {
if (ready == 1) {
line = line + 1;
}
if (ready == 0) {
ready = 1;
}
count = 0;
bod = 0;
dot = 0;
}
void skuska2() {
if (count < maxcount && ready == 1) {
count = count + 1;
} else if (count >= maxcount) {
count = maxcount;
}
}
void loop() {
bod = count / 3.00;
dot = count / 3;
totoff1 = dot + bodoff1;
totoff2 = dot + bodoff2;
totoff3 = dot + bodoff3;
totoff4 = dot + bodoff4;
totoff5 = dot + bodoff5;
totoff6 = dot + bodoff6;
totoff7 = dot + bodoff7;
totoff8 = dot + bodoff8;
if (bod - dot < 0.2 || ready == 1) { // don't forget to change || to &&
digitalWrite(4, pgm_read_byte(&testimg[line][totoff1]));
digitalWrite(5, pgm_read_byte(&testimg[line][totoff2]));
digitalWrite(6, pgm_read_byte(&testimg[line][totoff3]));
digitalWrite(7, pgm_read_byte(&testimg[line][totoff4]));
digitalWrite(8, pgm_read_byte(&testimg[line][totoff5]));
digitalWrite(9, pgm_read_byte(&testimg[line][totoff6]));
digitalWrite(10, pgm_read_byte(&testimg[line][totoff7]));
digitalWrite(11, pgm_read_byte(&testimg[line][totoff8]));
} 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(line > 98) {
val = 0;
ready == 0;
delay(500);
line = 0;
}
}