#include <Stepper.h>
#define STEPS 200
Stepper stepper(STEPS, 8, 10, 9, 11);
int urobilKrokov = 0;
int r = 2;
int g = 3;
int b = 4;
int button = 6;
int steps;
int dozadu;
bool stl = true;
/*const byte numChars = 32;
char receivedChars[numChars];
boolean newData = false;*/
void setup() {
stepper.setSpeed(60);
pinMode(r, OUTPUT);
pinMode(g, OUTPUT);
pinMode(b, OUTPUT);
pinMode(button, INPUT);
digitalWrite(button, HIGH);
Serial.begin(9600);
Serial.println("zadaj o kolko sa ma posunut:");
}
void loop()
{
/*bool value = digitalRead(button);*/
digitalWrite(r, LOW);
digitalWrite(g, HIGH);
if (Serial.available() > 0) {
String input = Serial.readStringUntil('\n');
input.trim();
if (input.length() > 0 && input.toInt() != 0) {
int steps = input.toInt();
urobilKrokov += steps;
stepper.step(steps);
Serial.print("Posunul o: ");
Serial.print(steps);
Serial.print(" krokov. Spravil: ");
Serial.println(urobilKrokov);
Serial.println("zadaj o kolko sa ma posunut:");
} else {
Serial.println("nezadal si cislo");
}
}
if (digitalRead(button) == LOW && stl == true)
{
digitalWrite(g, LOW);
digitalWrite(r, HIGH);
Serial.println("-------------------------------------");
Serial.println("Stepper sa vracia!");
stepper.step(-urobilKrokov);
urobilKrokov = 0;
Serial.println("Stepper sa vratil na hodnotu 0");
Serial.println("-------------------------------------");
Serial.println("zadaj o kolko sa ma posunut:");
}
if (digitalRead(5) != LOW && stl != true)
{
stl = true;
}
}
/*void recvWithEndMarker() {
static byte ndx = 0;
char endMarker = '\n';
char rc;
while (Serial.available() > 0 && newData == false) {
rc = Serial.read();
if (rc != endMarker) {
receivedChars[ndx] = rc;
ndx++;
if (ndx >= numChars) {
ndx = numChars - 1;
}
}
else {
receivedChars[ndx] = '\0'; // terminate the string
ndx = 0;
newData = true;
}
}
}
void showNewData() {
if (newData == true) {
Serial.print("This just in ... ");
Serial.println(receivedChars);
newData = false;
}
}*/