Back to Parent

int prePin = D1;
int motorPin = D6;
int sleepTime = 0;
int a = 0;
int b = 0;
int Start_sleepTime = 0;
int End_sleepTime = 0;
int lag = 0;
int value = 0;

unsigned long lastTime = 0;
int state = 0;
int excute = 0;


void setup(){
 Time.zone(-5);
 Serial.begin(9600);
 pinMode(prePin, INPUT);
 pinMode(motorPin, OUTPUT);
}

void loop(){
int tTime = Time.hour();

if(tTime >= 22 and tTime < 24){
 int preState = digitalRead(prePin);
 if(preState >= 4096 and state == 0){
   state = 1;
   a = 25- tTime;
   Start_sleepTime = Time.hour();
   delay(100);
 }
}

else if(tTime >= 0 and tTime <3){
 int preState = digitalRead(prePin);
 if(preState == 1 and state == 0){
   state = 1;
   a = 1;
   Start_sleepTime = Time.hour();
   delay(100);
 }
}

else if(tTime >= 3 and tTime <= 6){
 int preState = digitalRead(prePin);
 if(preState == 1 and state == 0){
   state = 1;
   a = 0;
   Start_sleepTime = Time.hour();
   delay(100);
 }
}

else if(tTime > 6 and tTime <= 10){
  int preState = digitalRead(prePin);
  if(preState == 0 and state ==1){
    state = 0;
    End_sleepTime = Time.hour();
    delay(100);
  }
}

else if(tTime > 10){
 if(excute == 0){
   int preState = digitalRead(prePin);
   if(preState == 1){
     b = 0;
   }
   if(Start_sleepTime >6){
     sleepTime = End_sleepTime - Start_sleepTime + 24;
   }
   else{
     sleepTime = End_sleepTime - Start_sleepTime;
   }
   if(sleepTime == 5 or 6){
     b = 0;
   }
   else if (sleepTime == 7 or 8 or 9){
     b = 2;
   }
   else if (sleepTime == 10 or 11 or 12){
     b = 1;
   }
   value = a*b;
   excute = 1;
 }

 else if(excute == 1){
    if (value = 0){
      digitalWrite(motorPin, LOW);
    }
    else if(value == 1 or 2 or 3){
      digitalWrite(motorPin, HIGH);
      delay(5000);
      digitalWrite(motorPin, LOW);
      delay(10000);
    }
    else if(value == 4 or 6){
      digitalWrite(motorPin, HIGH);
      delay(5000);
      digitalWrite(motorPin, LOW);
      delay(100);
    }
 }
}
}
Click to Expand

Content Rating

Is this a good/useful/informative piece of content to include in the project? Have your say!

0