1
2const int ledPin1 = 13;
3const int ledPin2=12;
4const int inputPin1 = 9;
5const int inputPin2=10;
6int SW1State ;
7int SW2State;
8int value1 = HIGH;
9int value2=LOW;
10
11void setup()
12{
13 pinMode(ledPin1, OUTPUT);
14 pinMode(ledPin2, OUTPUT);
15 pinMode(inputPin1, INPUT);
16 pinMode(inputPin2, INPUT);
17}
18
19void loop()
20 {
21 value1 = digitalRead(inputPin1);
22 value2 = digitalRead(inputPin2);
23 if (value1== HIGH)
24 SW1State = HIGH;
25 if (value1 == LOW)
26 SW1State = LOW;
27
28 if (value2== HIGH)
29 SW2State = HIGH;
30 if (value2 == LOW)
31 SW2State = LOW;
32 if(SW1State==HIGH)
33 {
34 digitalWrite(ledPin1,HIGH);
35 }
36 else
37 {
38 digitalWrite(ledPin1,LOW);
39
40 }
41
42 if(SW2State==HIGH)
43 {
44 digitalWrite(ledPin2,HIGH);
45 }
46 else
47 {
48 digitalWrite(ledPin2,LOW);
49
50 }
51
52 }
doug999
a year ago
Confused. Why are you using physical resistors ? Cannot this be done using software ? PULLUP