#include <Servo.h>
Servo myServo;
bool stavServo=false;
unsigned long MOVING_TIME = 2000;
unsigned long moveStartTime =0;
int startAngle = 0;
int stopAngle = 90;
String stav = "";
#define PIN A1
unsigned long previousMillis = 0;
void setup() {
Serial.begin(9600);
myServo.attach(9);
myServo.write(90);
delay(500);
moveStartTime = millis();
}
void loop() {
int hodnota = analogRead(A1);
int intenzita = map(hodnota,0,1023,0,90);
Serial.print("Teplota je: ");
Serial.print(intenzita);
Serial.println(" *C. ");
unsigned long progress = millis() - moveStartTime;
if(progress >= MOVING_TIME){
if(Serial.available()){
char c = Serial.read();
if(c == '\n'){
stav.trim();
if(stav.equalsIgnoreCase("left")){
myServo.write(0);
}
else if(stav.equalsIgnoreCase("right")){
myServo.write(180);
}
else if(stav.equalsIgnoreCase("center")){
myServo.write(90);
}
else{
}
stav = "";
}
else{
stav += c;
}
}
}
}