@@ -16,7 +16,7 @@ The Switch Control Library is intended to be used for hobby purposes only. Unde
1616
1717In 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:
1818
19- ![ Switch Table] ( /switch_table2.png )
19+ ![ Switch Table] ( /example_table.bmp )
2020
2121The system above can be setup in two different ways depending on user preference:
2222
@@ -39,54 +39,47 @@ elapsedMillis dt;
3939void setup()
4040{
4141 Serial.begin(115200);
42-
43- //Define pins for Heater
42+
4443 heater.defineInputPin(2);
45- heater.defineOutputPins(23);
46-
47- //Define pins for Camera
44+ heater.defineOutputPins(24);
45+
4846 camera.defineInputPin(3);
49- camera.defineOutputPins(24);
50-
51- //Define pins for Fan
47+ camera.defineOutputPins(25);
48+
5249 fan.setPositionName(0, "Low Speed");
5350 fan.setPositionName(1, "High Speed");
5451 fan.defineInputPin("Low Speed", 4);
55- fan.defineOutputPins("Low Speed", 25 );
52+ fan.defineOutputPins("Low Speed", 26 );
5653 fan.defineInputPin("High Speed", 5);
57- fan.defineOutputPins("High Speed", 26);
58-
59- //Define pins for Lights
54+ fan.defineOutputPins("High Speed", 27);
55+
6056 lights.setPositionName(0, "Day Mode");
6157 lights.setPositionName(1, "Night Mode");
6258 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");
7166 fan.setAlarm("Low Speed", 100000, 10000);
7267
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+
7771 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+
8174 Switch::_setInputActiveLevelAll(LOW);
8275 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+
8881 Switch::init(&timer);
89-
82+
9083 dt = 0;
9184}
9285```
@@ -98,64 +91,69 @@ void setup()
9891#include "Timer.h"
9992#include "string_Teensy.h"
10093
94+
10195Switch switch1(SwitchType::SPST, "Heater");
10296Switch switch2(SwitchType::SPST, "Camera");
10397Switch switch3(SwitchType::SPDT, "Fan", "Low Speed", "High Speed");
10498Switch switch4(SwitchType::SP3T, "Lights", "Day Mode", "Night Mode", "Timer");
10599
106- Timer;
100+ Timer timer ;
107101elapsedMillis dt;
108102
109103void setup()
110104{
111105 Serial.begin(115200);
112106 delay(6000);
113107 Serial.println("Switch Test Begin...");
114-
115108 //Define pins for Heater
116109 Switch::_defineInputPin("Heater", 2);
117- Switch::_defineOutputPins("Heater", 23 );
110+ Switch::_defineOutputPins("Heater", 24 );
118111
119112 //Define pins for Camera
120113 Switch::_defineInputPin("Camera", 3);
121- Switch::_defineOutputPins("Camera", 24 );
114+ Switch::_defineOutputPins("Camera", 25 );
122115
123116 //Define pins for Fan
124117 Switch::_defineInputPin("Fan", "Low Speed", 4);
125- Switch::_defineOutputPins("Fan", "Low Speed", 25 );
118+ Switch::_defineOutputPins("Fan", "Low Speed", 26 );
126119 Switch::_defineInputPin("Fan", "High Speed", 5);
127- Switch::_defineOutputPins("Feeder", "High Speed", 26 );
120+ Switch::_defineOutputPins("Feeder", "High Speed", 27 );
128121
129122 //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");
138131 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);
139136
140137 //Add external trigger alarm for Camera
141138 Switch::_addAlarm(SwitchAlarm::External, "Camera");
142139
143140 //Configure alarm for Lights
144141 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 ");
146143
147144 //Set active input and output logic levels for switches
148145 Switch::_setInputActiveLevelAll(LOW);
149146 Switch::_setOutputActiveLevelAll(LOW);
150147
151148 //Provide current utc unix time to Timer class
152- timer.setCurrentTime(1559851450);
149+ timer.setTimeZone("Eastern");
150+ timer.setDST(true);
151+ timer.setCurrentTime(1561224930);
153152
154153 //Initialize switches
155154 Switch::init(&timer);
156155
157156 dt = 0;
158-
159157}
160158```
161159## Loop Methods
0 commit comments