-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathToggleSwitchExample.ino
59 lines (49 loc) · 1.56 KB
/
ToggleSwitchExample.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
// Include the library
#include <VirtualButton.h>
// Used to define how many switches the Arduino will handle
const byte SWITCH_COUNT = 3;
// Used to store if the virutal toggle switch is ON (true)
// NOTE: By default they are all false (OFF)
bool toggleSwitchON[SWITCH_COUNT];
// Set up the VirtualButton class
VirtualButton vb(toggleSwitchON);
void setup() {
// Set up the serial monitor
Serial.begin(9600);
// Loop through the initial array and display the values
Serial.println("Initial array values:");
for (int i = 0; i < SWITCH_COUNT; i++) {
Serial.print(toggleSwitchON[i]);
if (i != SWITCH_COUNT - 1)
Serial.print(", ");
else
Serial.println();
}
// Toggle the first switch (the switch at index 0)
vb.toggleSwitch(0);
// Loop through the initial array and display the values after calling toggleSwitch() for the 1st switch
Serial.println("Array after toggling switch 1:");
for (int i = 0; i < SWITCH_COUNT; i++) {
Serial.print(toggleSwitchON[i]);
if (i != SWITCH_COUNT - 1)
Serial.print(", ");
else
Serial.println();
}
// Loop through each switch and toggle it
for (int i = 0; i < SWITCH_COUNT; i++) {
vb.toggleSwitch(i);
}
// Loop through the initial array and display the values after calling toggleSwitch() for all the switches
Serial.println("Array after toggling all the switches:");
for (int i = 0; i < SWITCH_COUNT; i++) {
Serial.print(toggleSwitchON[i]);
if (i != SWITCH_COUNT - 1)
Serial.print(", ");
else
Serial.println();
}
}
void loop() {
// Do nothing
}