Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- int mtrDO = 6, mtrDC = 7, mtrTO = 10,mtrTC = 11; //The motor outputs
- int openState = 0, twistState = 0; //Moniters when blinds are open and closed
- int swtchOC = 1; //The switch for opening and closing the blinds
- int swtchT = 8; //The switch for twisting open and closed the blinds
- int swtchAM = 4; //The auto/manual switch
- int lightDetect = 5; //The photoresistor
- 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)
- void setup() {
- pinMode(mtrDO, OUTPUT);
- pinMode(mtrDC, OUTPUT);
- pinMode(mtrTO, OUTPUT);
- pinMode(mtrTC, OUTPUT);
- pinMode(swtchOC, INPUT);
- pinMode(swtchT, INPUT);
- pinMode(lightDetect,INPUT);
- pinMode(swtchAM, INPUT);
- }
- void loop() {
- mode = digitalRead(swtchAM); //Stores Auto/Manual switch status
- if(mode == HIGH){ //Checks if switch is set to Manual (HIGH)
- modeM = digitalRead(swtchOC); //Stores Open/Closed switch status
- modeT = digitalRead(swtchT); //Stores Twist Switch switch statusChecks if switch is set to Twist Open or Close (
- 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)
- digitalWrite(mtrDO, HIGH); //Turns Motor to open
- delay(3000); //Waits 3seconds
- digitalWrite(mtrDO,LOW); //Turns off Motor
- openState = 1; //Sets that blinds are moved open
- }
- else if(modeM == LOW && openState == 1){//Checks if switch is set to Closed (LOW) and if openState is 1 (currently open)
- digitalWrite(mtrDC, HIGH); //Turns Motor to close
- delay(3000); //Waits 3seconds
- digitalWrite(mtrDC,LOW); //Turns off Motor
- openState = 0; //Sets that blinds are moved closed
- }
- if(modeT == HIGH && twistState == 0){ //Checks if switch is set to Open (HIGH) and if twistState is 0 (currently closed)
- digitalWrite(mtrTO, HIGH);
- delay(3000);
- digitalWrite(mtrTO,LOW);
- twistState = 1; //Sets that blinds are twisted open
- }
- 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)
- digitalWrite(mtrTC, HIGH); //closes blinds twist
- delay(3000);
- digitalWrite(mtrTC,LOW);
- twistState = 0; //Sets that blinds are twisted closed
- }
- }
- else if(mode == LOW){ //Checks if switch is set to Automatic (LOW)
- if (openState == 1){ //Checks if blinds are drawn open
- digitalWrite(mtrDC, HIGH); //Turns Motor to close
- delay(3000); //Waits 3seconds
- digitalWrite(mtrDC,LOW); //Turns off Motor
- openState = 0; //Sets that blinds are moved closed
- }
- else if (openState == 0){ //Checks that blinds are closed
- modeL = digitalRead(lightDetect); //measures light
- if(modeL == LOW && twistState == 1){ //if low light and blinds twisted open then
- digitalWrite(mtrTC, HIGH); //motors close blinds
- delay(1000);
- digitalWrite(mtrTC, LOW);
- twistState = 0; //set state to closed
- }
- else if(modeL == HIGH && twistState == 0){//if bright light and blinds closed
- digitalWrite(mtrTO, HIGH); //motors open blinds
- delay(1000);
- digitalWrite(mtrTO, LOW);
- twistState = 1; //set state to open
- }
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement