-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathswitchTest.ino
More file actions
42 lines (30 loc) · 951 Bytes
/
switchTest.ino
File metadata and controls
42 lines (30 loc) · 951 Bytes
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
// define LED pin ports (output)
#define LED_PIN1 32
#define LED_PIN2 31
#define LED_PIN3 30
#define LED_PIN4 29
// define switch port (input)
#define SwitchIn 34
int switchState = 0; // stores if switch is in the true or false position
void setup() {
// Configure LED ports
pinMode(LED_PIN1, OUTPUT); // set pin 32 as an ouput
pinMode(LED_PIN2, OUTPUT); // set pin 31 as an output
pinMode(LED_PIN3, OUTPUT); // set pin 30 as an output
pinMode(LED_PIN4, OUTPUT); // set pin 29 as an output
// Configure switch port
pinMode(SwitchIn, INPUT); // set port () as an input
} // void setup()
void loop() {
// read switch state
switchState = digitalRead(SwitchIn);
// enter pattern if switch state is true
if (switchState == HIGH) {
analogWrite(LED_PIN1, 200);
analogWrite(LED_PIN2, 200);
} // if (switchState == HIGH)
else {
analogWrite(LED_PIN1, 0);
analogWrite(LED_PIN2, 0);
}
} // void loop()