@@ -16,7 +16,7 @@ The Switch Control Library is intended to be used for hobby purposes only. Unde
16
16
17
17
In the above example, there are two SPST switches, one SPDT switch and one SP3T switch with input signals feeding into pull-up pins on a Teensy 3.6. When a particular switch position is in the “active” state, it means that its associated pull-up pin is pulled LOW. Let’s configure our system to work in the following manner:
18
18
19
- ![ Switch Table] ( /switch_table2.png )
19
+ ![ Switch Table] ( /example_table.bmp )
20
20
21
21
The system above can be setup in two different ways depending on user preference:
22
22
@@ -39,54 +39,47 @@ elapsedMillis dt;
39
39
void setup()
40
40
{
41
41
Serial.begin(115200);
42
-
43
- //Define pins for Heater
42
+
44
43
heater.defineInputPin(2);
45
- heater.defineOutputPins(23);
46
-
47
- //Define pins for Camera
44
+ heater.defineOutputPins(24);
45
+
48
46
camera.defineInputPin(3);
49
- camera.defineOutputPins(24);
50
-
51
- //Define pins for Fan
47
+ camera.defineOutputPins(25);
48
+
52
49
fan.setPositionName(0, "Low Speed");
53
50
fan.setPositionName(1, "High Speed");
54
51
fan.defineInputPin("Low Speed", 4);
55
- fan.defineOutputPins("Low Speed", 25 );
52
+ fan.defineOutputPins("Low Speed", 26 );
56
53
fan.defineInputPin("High Speed", 5);
57
- fan.defineOutputPins("High Speed", 26);
58
-
59
- //Define pins for Lights
54
+ fan.defineOutputPins("High Speed", 27);
55
+
60
56
lights.setPositionName(0, "Day Mode");
61
57
lights.setPositionName(1, "Night Mode");
62
58
lights.setPositionName(2, "Timer");
63
- lights.defineInputPin("Day Mode", 28);
64
- lights.defineOutputPins("Day Mode", 37);
65
- lights.defineInputPin("Night Mode", 29);
66
- lights.defineOutputPins("Night Mode", 38);
67
- lights.defineOutputPins("Timer", 37);
68
-
69
- //Configure alarm for Fan
70
- fan.addAlarm(SwitchAlarm::Stopwatch, "Low Speed");
59
+ lights.defineInputPin("Day Mode", 6);
60
+ lights.defineOutputPins("Day Mode", 28);
61
+ lights.defineInputPin("Night Mode", 7);
62
+ lights.defineOutputPins("Night Mode", 30);
63
+ lights.defineOutputPins("Timer", 28);
64
+
65
+ fan.addAlarm(SwitchAlarm::Stopwatch_Interval, "Low Speed");
71
66
fan.setAlarm("Low Speed", 100000, 10000);
72
67
73
- //Add external trigger for Camera
74
- fan.addAlarm(SwitchAlarm::External);
75
-
76
- //Configure alarm for Lights
68
+ fan.addAlarm(SwitchAlarm::Stopwatch_Clock, "High Speed");
69
+ fan.setAlarm("High Speed", "13:38:00", 10000);
70
+
77
71
lights.addAlarm(SwitchAlarm::Toggler, "Timer");
78
- lights.setAlarm("Timer", "07:00:00", "19:01:00");
79
-
80
- //Set active input and output logic levels for switches
72
+ lights.setAlarm("Timer", "13:36:30", "13:37:30");
73
+
81
74
Switch::_setInputActiveLevelAll(LOW);
82
75
Switch::_setOutputActiveLevelAll(LOW);
83
-
84
- //Provide current utc unix time to Timer class
85
- timer.setCurrentTime(1559851450 );
86
-
87
- //Initialize switches
76
+
77
+ timer.setTimeZone("Eastern");
78
+ timer.setDST(true );
79
+ timer.setCurrentTime(1561224930);
80
+
88
81
Switch::init(&timer);
89
-
82
+
90
83
dt = 0;
91
84
}
92
85
```
@@ -98,64 +91,69 @@ void setup()
98
91
#include "Timer.h"
99
92
#include "string_Teensy.h"
100
93
94
+
101
95
Switch switch1(SwitchType::SPST, "Heater");
102
96
Switch switch2(SwitchType::SPST, "Camera");
103
97
Switch switch3(SwitchType::SPDT, "Fan", "Low Speed", "High Speed");
104
98
Switch switch4(SwitchType::SP3T, "Lights", "Day Mode", "Night Mode", "Timer");
105
99
106
- Timer;
100
+ Timer timer ;
107
101
elapsedMillis dt;
108
102
109
103
void setup()
110
104
{
111
105
Serial.begin(115200);
112
106
delay(6000);
113
107
Serial.println("Switch Test Begin...");
114
-
115
108
//Define pins for Heater
116
109
Switch::_defineInputPin("Heater", 2);
117
- Switch::_defineOutputPins("Heater", 23 );
110
+ Switch::_defineOutputPins("Heater", 24 );
118
111
119
112
//Define pins for Camera
120
113
Switch::_defineInputPin("Camera", 3);
121
- Switch::_defineOutputPins("Camera", 24 );
114
+ Switch::_defineOutputPins("Camera", 25 );
122
115
123
116
//Define pins for Fan
124
117
Switch::_defineInputPin("Fan", "Low Speed", 4);
125
- Switch::_defineOutputPins("Fan", "Low Speed", 25 );
118
+ Switch::_defineOutputPins("Fan", "Low Speed", 26 );
126
119
Switch::_defineInputPin("Fan", "High Speed", 5);
127
- Switch::_defineOutputPins("Feeder", "High Speed", 26 );
120
+ Switch::_defineOutputPins("Feeder", "High Speed", 27 );
128
121
129
122
//Define pins for Lights
130
- Switch::_defineInputPin("Lights", "Day Mode", 28 );
131
- Switch::_defineOutputPins("Lights", "Day Mode", 37 );
132
- Switch::_defineInputPin("Lights", "Night Mode", 29 );
133
- Switch::_defineOutputPins("Lights", "Night Mode", 38 );
134
- Switch::_defineOutputPins("Lights", "Timer", 37 );
135
-
136
- //Configure alarm for Fan
137
- Switch::_addAlarm(SwitchAlarm::Stopwatch , "Fan", "Low Speed");
123
+ Switch::_defineInputPin("Lights", "Day Mode", 6 );
124
+ Switch::_defineOutputPins("Lights", "Day Mode", 28 );
125
+ Switch::_defineInputPin("Lights", "Night Mode", 7 );
126
+ Switch::_defineOutputPins("Lights", "Night Mode", 30 );
127
+ Switch::_defineOutputPins("Lights", "Timer", 28 );
128
+
129
+ //Configure alarm for Low-Speed Fan Position
130
+ Switch::_addAlarm(SwitchAlarm::Stopwatch_Interval , "Fan", "Low Speed");
138
131
Switch::_setAlarm("Fan", "Low Speed", 100000, 10000);
132
+
133
+ //Configure alarm for High-Speed Fan Position
134
+ Switch::_addAlarm(SwitchAlarm::Stopwatch_Clock, "Fan", "High Speed");
135
+ Switch::_setAlarm("Fan", "High Speed", "13:38:00", 10000);
139
136
140
137
//Add external trigger alarm for Camera
141
138
Switch::_addAlarm(SwitchAlarm::External, "Camera");
142
139
143
140
//Configure alarm for Lights
144
141
Switch::_addAlarm(SwitchAlarm::Toggler, "Lights", "Timer");
145
- Switch::_setAlarm("Lights", "Timer", "07:00:00 ", "19:01:00 ");
142
+ Switch::_setAlarm("Lights", "Timer", "13:36:30 ", "13:37:30 ");
146
143
147
144
//Set active input and output logic levels for switches
148
145
Switch::_setInputActiveLevelAll(LOW);
149
146
Switch::_setOutputActiveLevelAll(LOW);
150
147
151
148
//Provide current utc unix time to Timer class
152
- timer.setCurrentTime(1559851450);
149
+ timer.setTimeZone("Eastern");
150
+ timer.setDST(true);
151
+ timer.setCurrentTime(1561224930);
153
152
154
153
//Initialize switches
155
154
Switch::init(&timer);
156
155
157
156
dt = 0;
158
-
159
157
}
160
158
```
161
159
## Loop Methods
0 commit comments