1const int button1 = 2;
2const int
3 button2 = 3;
4const int button3 = 4;
5 number of button 3 pin
6const int red = 8;
7const
8 int green = 9;
9const int blue = 10;
10 number of the blue pin
11
12
13int a = 0;
14 variable for reading the pushbutton status
15int b = 0;
16int c = 0;
17
18void
19 setup() {
20 Serial.begin(9600);
21
22
23 pinMode(red, OUTPUT);
24 pinMode(green, OUTPUT);
25 pinMode(blue, OUTPUT);
26
27
28 pinMode(button1, INPUT);
29
30 pinMode(button2, INPUT);
31 pinMode(button3, INPUT);
32}
33
34void loop()
35 {
36
37 a = digitalRead(button1);
38
39 b = digitalRead(button2);
40 c = digitalRead(button3);
41
42
43 state of pushbuttons on serial monitor
44 Serial.println(a);
45 Serial.println(b);
46
47 Serial.println(c);
48
49
50
51 it is, the buttonState is HIGH:
52 if (a == HIGH) {
53
54
55 digitalWrite(red, HIGH);
56 } else {
57
58 digitalWrite(red,
59 LOW);
60 }
61 if (b == HIGH) {
62 digitalWrite(green, HIGH);
63 } else
64 {
65 digitalWrite(green, LOW);
66 }
67 if (c == HIGH) {
68 digitalWrite(blue,
69 HIGH);
70 } else {
71 digitalWrite(blue, LOW);
72 }
73
74 so that we can see the output of button
75 delay(100);
76}