SHOW:
|
|
- or go back to the newest paste.
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 | - | pinMode(mtrDO, OUTPUT); |
9 | + | |
10 | - | pinMode(mtrDC, OUTPUT); |
10 | + | pinMode(mtrDO, OUTPUT); |
11 | - | pinMode(mtrTO, OUTPUT); |
11 | + | pinMode(mtrDC, OUTPUT); |
12 | - | pinMode(mtrTC, OUTPUT); |
12 | + | pinMode(mtrTO, OUTPUT); |
13 | - | pinMode(swtchOC, INPUT); |
13 | + | pinMode(mtrTC, OUTPUT); |
14 | - | pinMode(swtchT, INPUT); |
14 | + | pinMode(swtchOC, INPUT); |
15 | - | pinMode(lightDetect,INPUT); |
15 | + | pinMode(swtchT, INPUT); |
16 | - | pinMode(swtchAM, INPUT); |
16 | + | pinMode(lightDetect,INPUT); |
17 | pinMode(swtchAM, INPUT); | |
18 | } | |
19 | ||
20 | - | mode = digitalRead(swtchAM); //Stores Auto/Manual switch status |
20 | + | |
21 | mode = digitalRead(swtchAM); //Stores Auto/Manual switch status | |
22 | - | if(mode == HIGH){ //Checks if switch is set to Manual (HIGH) |
22 | + | |
23 | - | modeM = digitalRead(swtchOC); //Stores Open/Closed switch status |
23 | + | if(mode == HIGH){ //Checks if switch is set to Manual (HIGH) |
24 | - | modeT = digitalRead(swtchT); //Stores Twist Switch switch statusChecks if switch is set to Twist Open or Close ( |
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 | - | 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) |
26 | + | |
27 | - | digitalWrite(mtrDO, HIGH); //Turns Motor to open |
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 | - | delay(3000); //Waits 3seconds |
28 | + | digitalWrite(mtrDO, HIGH); //Turns Motor to open |
29 | - | digitalWrite(mtrDO,LOW); //Turns off Motor |
29 | + | delay(3000); //Waits 3seconds |
30 | - | openState = 1; //Sets that blinds are moved open |
30 | + | digitalWrite(mtrDO,LOW); //Turns off Motor |
31 | - | } |
31 | + | openState = 1; //Sets that blinds are moved open |
32 | } | |
33 | - | else if(modeM == LOW&&openState == 1){//Checks if switch is set to Closed (LOW) and if openState is 1 (currently open) |
33 | + | |
34 | - | digitalWrite(mtrDC, HIGH); //Turns Motor to close |
34 | + | else if(modeM == LOW&&openState == 1){//Checks if switch is set to Closed (LOW) and if openState is 1 (currently open) |
35 | - | delay(3000); //Waits 3seconds |
35 | + | digitalWrite(mtrDC, HIGH); //Turns Motor to close |
36 | - | digitalWrite(mtrDC,LOW); //Turns off Motor |
36 | + | delay(3000); //Waits 3seconds |
37 | - | openState = 0; //Sets that blinds are moved closed |
37 | + | digitalWrite(mtrDC,LOW); //Turns off Motor |
38 | - | } |
38 | + | openState = 0; //Sets that blinds are moved closed |
39 | } | |
40 | - | if(modeT == HIGH&&twistState == 0){ //Checks if switch is set to Open (HIGH) and if twistState is 0 (currently closed) |
40 | + | |
41 | - | digitalWrite(mtrTO, HIGH); |
41 | + | if(modeT == HIGH&&twistState == 0){ //Checks if switch is set to Open (HIGH) and if twistState is 0 (currently closed) |
42 | - | delay(3000); |
42 | + | digitalWrite(mtrTO, HIGH); |
43 | - | digitalWrite(mtrTO,LOW); |
43 | + | delay(3000); |
44 | - | twistState = 1; //Sets that blinds are twisted open |
44 | + | digitalWrite(mtrTO,LOW); |
45 | - | } |
45 | + | twistState = 1; //Sets that blinds are twisted open |
46 | } | |
47 | - | 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) |
47 | + | |
48 | - | digitalWrite(mtrTC, HIGH); //closes blinds twist |
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 | - | delay(3000); |
49 | + | digitalWrite(mtrTC, HIGH); //closes blinds twist |
50 | - | digitalWrite(mtrTC,LOW); |
50 | + | delay(3000); |
51 | - | twistState = 0; //Sets that blinds are twisted closed |
51 | + | digitalWrite(mtrTC,LOW); |
52 | - | } |
52 | + | twistState = 0; //Sets that blinds are twisted closed |
53 | } | |
54 | } | |
55 | - | else if(mode == LOW){ //Checks if switch is set to Automatic (LOW) |
55 | + | |
56 | - | if (openState == 1){ //Checks if blinds are drawn open |
56 | + | else if(mode == LOW){ //Checks if switch is set to Automatic (LOW) |
57 | - | digitalWrite(mtrDC, HIGH); //Turns Motor to close |
57 | + | if (openState == 1){ //Checks if blinds are drawn open |
58 | - | delay(3000); //Waits 3seconds |
58 | + | digitalWrite(mtrDC, HIGH); //Turns Motor to close |
59 | - | digitalWrite(mtrDC,LOW); //Turns off Motor |
59 | + | delay(3000); //Waits 3seconds |
60 | - | openState = 0; //Sets that blinds are moved closed |
60 | + | digitalWrite(mtrDC,LOW); //Turns off Motor |
61 | - | } |
61 | + | openState = 0; //Sets that blinds are moved closed |
62 | - | else if (openState == 0){ //Checks that blinds are closed |
62 | + | } |
63 | - | modeL = digitalRead(lightDetect); //measures light |
63 | + | |
64 | - | if(modeL == LOW && twistState == 1){ //if low light and blinds twisted open then |
64 | + | else if (openState == 0){ //Checks that blinds are closed |
65 | - | digitalWrite(mtrTC, HIGH); //motors close blinds |
65 | + | modeL = digitalRead(lightDetect); //measures light |
66 | - | delay(1000); |
66 | + | if(modeL == LOW && twistState == 1){ //if low light and blinds twisted open then |
67 | - | digitalWrite(mtrTC, LOW); |
67 | + | digitalWrite(mtrTC, HIGH); //motors close blinds |
68 | - | twistState = 0; //set state to closed |
68 | + | delay(1000); |
69 | - | } |
69 | + | digitalWrite(mtrTC, LOW); |
70 | - | else if(modeL == HIGH && twistState == 0){//if bright light and blinds closed |
70 | + | twistState = 0; //set state to closed |
71 | - | digitalWrite(mtrTO, HIGH); //motors open blinds |
71 | + | } |
72 | - | delay(1000); |
72 | + | |
73 | - | digitalWrite(mtrTO, LOW); |
73 | + | else if(modeL == HIGH && twistState == 0){//if bright light and blinds closed |
74 | - | twistState = 1; //set state to open |
74 | + | digitalWrite(mtrTO, HIGH); //motors open blinds |
75 | - | } |
75 | + | delay(1000); |
76 | - | } |
76 | + | digitalWrite(mtrTO, LOW); |
77 | - | } |
77 | + | twistState = 1; //set state to open |
78 | } | |
79 | } | |
80 | } | |
81 | } |