#include <Servo.h>

#define LED_RED 13//2
#define LED_GREEN  3
#define LED_BLUE  4

#define WATER_POWER 9
#define WATER_TEMP 10

String voice;

// Create a servo object
Servo power, temp;
int p=0,t=90;
int durmax=300;
int durmin=100;

void blink(int led, int time){
  digitalWrite(led,HIGH);
  delay(time);
  digitalWrite(led, LOW);
}

void TempUp(){
  if(t<176){
   t+=5;
   temp.write(t);
   Serial.println(t);
   digitalWrite(LED_GREEN, HIGH);
   delay(300);
   digitalWrite(LED_GREEN, LOW);
   blink(LED_GREEN,durmax);
  }
}

void TempDown(){
  if(t>5){
    t=t-5;
    temp.write(t);
    Serial.println(t);
    blink(LED_GREEN,durmin);
  }
}

void PowerUp() {
  if(p<176){
    p=p+5;
    power.write(p);
    Serial.println(p);
    blink(LED_BLUE,durmax);
  }
}

void PowerDown(){
  if(p>5){
    p=p-5;
    power.write(p);
    Serial.println(p);
    blink(LED_BLUE,durmin);
  }
}

void Comfort(){
  p=120;
  t=105;
  temp.write(t);
  power.write(p);
  Serial.println(t);
  Serial.println(p);
  blink(LED_RED,durmax);
  
}

void CloseW(){
  p=0;
  t=90;
  temp.write(t);
  power.write(p);
  Serial.println(t);
  Serial.println(p);
  blink(LED_RED,durmin);
}

void Error(){
  Serial.println("ERROR");
  blink(LED_RED,durmin);
  blink(LED_GREEN,durmin);
  blink(LED_BLUE,durmin);
}

void setup() {
  Serial.begin(9600);
  Serial.println("Working...");
  pinMode(LED_RED, OUTPUT);
  pinMode(LED_GREEN, OUTPUT);
  pinMode(LED_BLUE, OUTPUT);

  power.attach(WATER_POWER);
  power.write(p);
  temp.attach(WATER_TEMP);
  temp.write(t);


  delay(10);
}

void loop() {
  while (Serial.available()) {
    delay(10);
    char c = Serial.read();
    if (c == '#')
    {
      break;
    }
    voice += c;
  }
  if (voice.length() > 0) {
    Serial.println(voice);
    if (voice == "UP")
    {
      PowerUp();
    }
    else if (voice == "DOWN")
    {
      PowerDown();
    }
    else if (voice == "RIGHT") {
      TempUp();
    }
    else if (voice == "LEFT") {
      TempDown();
    }
    else if (voice == "FAR") {
      CloseW();
      
    }
    else if (voice == "NEAR") {
      Comfort();
    }
    else if (voice == "NONE") {
      Error();
    }
    voice = "";
  }
}
$abcdeabcde151015202530fghijfghij