int fan1 = 5;
int fan2 = 6;
int fan3 = 7;
int fan4 = 8;
int fan5 = 9;
int fan6 = 10;

int potPin = A0;
int potValue;
int lightSensorPin = A1;
int lightSensor;
int serialvalue;

int startTime = 0;
int interval = 1000;

boolean keepwarmState = HIGH;
boolean lowState1 = HIGH;
boolean lowState2 = LOW;
boolean highState = LOW;

void setup() {
  Serial.begin(9600);
  pinMode(fan1, OUTPUT);
  pinMode(fan2, OUTPUT);
  pinMode(fan3, OUTPUT);
  pinMode(fan4, OUTPUT);
  pinMode(fan5, OUTPUT);
  pinMode(fan6, OUTPUT);


}

void loop() {
  lightSensor = analogRead(lightSensorPin);
  potValue = analogRead(potPin);

  //test need
  //Serial.print("pot= ");
  Serial.println(potValue);

  //test need
  //Serial.print("lightSensor= ");
  // Serial.println(lightSensor);


  //keep warm
  if (potValue > 0 && potValue <= 400) {

    digitalWrite(fan1, keepwarmState);
    digitalWrite(fan2, keepwarmState);
    digitalWrite(fan3, keepwarmState);
    digitalWrite(fan4, keepwarmState);
    digitalWrite(fan5, keepwarmState);
    digitalWrite(fan6, keepwarmState);
    if ((millis() - startTime) > interval)
    {
      keepwarmState = !keepwarmState;
      startTime = millis();
    }
  }

  //low state
  if (potValue >  400 && potValue <= 560) {

    digitalWrite(fan1, lowState1);
    digitalWrite(fan4, lowState1);
    digitalWrite(fan5, HIGH);
    digitalWrite(fan2, LOW);
    digitalWrite(fan3, lowState2);
    digitalWrite(fan6, lowState2);
    if (Serial.available()) // check to see if there's serial data in the buffer
    {
      serialvalue = Serial.read(); // read a byte of serial data
      lowState1 = !lowState1;
      lowState2 = !lowState2;
    }

  }


  //high state
  if (potValue > 560 && potValue <= 1023) {
    digitalWrite(fan3, HIGH);
    digitalWrite(fan6, HIGH);
    digitalWrite(fan2, highState);
    digitalWrite(fan4, LOW);
    digitalWrite(fan5, LOW);
    digitalWrite(fan1, highState);
    if (Serial.available()) // check to see if there's serial data in the buffer
    {
      serialvalue = Serial.read(); // read a byte of serial data
      highState = !highState;
    }
  }


}