Advertisement
Guest User

Untitled

a guest
Dec 4th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. int mtrDO = 6, mtrDC = 7, mtrTO = 10,mtrTC = 11; //The motor outputs
  2. int openState = 0, twistState = 0; //Moniters when blinds are open and closed
  3. int swtchOC = 1; //The switch for opening and closing the blinds
  4. int swtchT = 8;  //The switch for twisting open and closed the blinds
  5. int swtchAM = 4; //The auto/manual switch
  6. int lightDetect = 5; //The photoresistor
  7. int mode = 0, modeM = 0, modeT = 0,modeL = 0; //The values to hold the switch status (manual/auto, open/closed, twist open/twist closed, light)
  8.  
  9. void setup() {
  10.     pinMode(mtrDO, OUTPUT);
  11.     pinMode(mtrDC, OUTPUT);
  12.     pinMode(mtrTO, OUTPUT);
  13.     pinMode(mtrTC, OUTPUT);
  14.     pinMode(swtchOC, INPUT);
  15.     pinMode(swtchT, INPUT);
  16.     pinMode(lightDetect,INPUT);
  17.     pinMode(swtchAM, INPUT);
  18. }
  19.  
  20. void loop() {
  21.     mode = digitalRead(swtchAM); //Stores Auto/Manual switch status
  22.  
  23.     if(mode == HIGH){                   //Checks if switch is set to Manual (HIGH)
  24.         modeM = digitalRead(swtchOC);     //Stores Open/Closed switch status
  25.         modeT = digitalRead(swtchT);      //Stores Twist Switch switch statusChecks if switch is set to Twist Open or Close (
  26.    
  27.         if(modeM == HIGH && openState == 0 && twistState == 1){  //Checks if switch is set to Open (HIGH) and if openState is 0 (currently closed), and makes sure that blinds are twisted open (1)
  28.             digitalWrite(mtrDO, HIGH);          //Turns Motor to open
  29.             delay(3000);                        //Waits 3seconds
  30.             digitalWrite(mtrDO,LOW);            //Turns off Motor
  31.             openState = 1;                      //Sets that blinds are moved open
  32.         }
  33.  
  34.         else if(modeM == LOW && openState == 1){//Checks if switch is set to Closed (LOW) and if openState is 1 (currently open)
  35.             digitalWrite(mtrDC, HIGH);          //Turns Motor to close
  36.             delay(3000);                        //Waits 3seconds
  37.             digitalWrite(mtrDC,LOW);            //Turns off Motor
  38.             openState = 0;                      //Sets that blinds are moved closed
  39.         }
  40.  
  41.         if(modeT == HIGH && twistState == 0){ //Checks if switch is set to Open (HIGH) and if twistState is 0 (currently closed)
  42.             digitalWrite(mtrTO, HIGH);
  43.             delay(3000);
  44.             digitalWrite(mtrTO,LOW);
  45.             twistState = 1;                   //Sets that blinds are twisted open
  46.         }
  47.  
  48.         else if(modeT == LOW && twistState == 1 && openState==0){//Checks if switch is set to Closed (LOW) and if twistState is 1 (currently open) and if the blinds are closed (0)
  49.             digitalWrite(mtrTC, HIGH);        //closes blinds twist
  50.             delay(3000);
  51.             digitalWrite(mtrTC,LOW);
  52.             twistState = 0;                    //Sets that blinds are twisted closed
  53.         }
  54.     }
  55.  
  56.     else if(mode == LOW){              //Checks if switch is set to Automatic (LOW)
  57.         if (openState == 1){               //Checks if blinds are drawn open
  58.             digitalWrite(mtrDC, HIGH);          //Turns Motor to close
  59.             delay(3000);                        //Waits 3seconds
  60.             digitalWrite(mtrDC,LOW);            //Turns off Motor
  61.             openState = 0;                      //Sets that blinds are moved closed
  62.         }
  63.  
  64.         else if (openState == 0){         //Checks that blinds are closed
  65.             modeL = digitalRead(lightDetect);   //measures light
  66.             if(modeL == LOW && twistState == 1){ //if low light and blinds twisted open then
  67.                 digitalWrite(mtrTC, HIGH);          //motors close blinds
  68.                 delay(1000);
  69.                 digitalWrite(mtrTC, LOW);
  70.                 twistState = 0;                 //set state to closed
  71.             }
  72.            
  73.             else if(modeL == HIGH && twistState == 0){//if bright light and blinds closed    
  74.                 digitalWrite(mtrTO, HIGH);            //motors open blinds
  75.                 delay(1000);
  76.                 digitalWrite(mtrTO, LOW);
  77.                 twistState = 1;                    //set state to open
  78.             }
  79.         }
  80.     }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement