1
2
3
4int RXdata = 0;
5
6void setup() {
7
8
9 for (int i = 2; i < 6; i++){
10 pinMode(i, OUTPUT);
11 }
12
13 Serial.begin(9600);
14}
15
16void loop() {
17
18
19 if(Serial.available() > 0){
20 RXdata = Serial.read();
21 Serial.print(RXdata, DEC);
22
23 switch(RXdata){
24 case '0':
25
26 digitalWrite(2, LOW);
27 digitalWrite(3, LOW);
28 digitalWrite(4, LOW);
29 digitalWrite(5, LOW);
30 break;
31 case '1':
32
33 digitalWrite(2, HIGH);
34 digitalWrite(3, LOW);
35 digitalWrite(4, LOW);
36 digitalWrite(5, LOW);
37 break;
38 case '2':
39
40 digitalWrite(2, LOW);
41 digitalWrite(3, HIGH);
42 digitalWrite(4, LOW);
43 digitalWrite(5, LOW);
44 break;
45 case '3':
46
47 digitalWrite(2, HIGH);
48 digitalWrite(3, HIGH);
49 digitalWrite(4, LOW);
50 digitalWrite(5, LOW);
51 break;
52 case '4':
53
54 digitalWrite(2, LOW);
55 digitalWrite(3, LOW);
56 digitalWrite(4, HIGH);
57 digitalWrite(5, LOW);
58 break;
59 case '5':
60
61 digitalWrite(2, HIGH);
62 digitalWrite(3, LOW);
63 digitalWrite(4, HIGH);
64 digitalWrite(5, LOW);
65 break;
66 case '6':
67
68 digitalWrite(2, LOW);
69 digitalWrite(3, HIGH);
70 digitalWrite(4, HIGH);
71 digitalWrite(5, LOW);
72 break;
73 case '7':
74
75 digitalWrite(2, HIGH);
76 digitalWrite(3, HIGH);
77 digitalWrite(4, HIGH);
78 digitalWrite(5, LOW);
79 break;
80 case '8':
81
82 digitalWrite(2, LOW);
83 digitalWrite(3, LOW);
84 digitalWrite(4, LOW);
85 digitalWrite(5, HIGH);
86 break;
87 case '9':
88
89 digitalWrite(2, HIGH);
90 digitalWrite(3, LOW);
91 digitalWrite(4, LOW);
92 digitalWrite(5, HIGH);
93 break;
94 }
95 }
96
97}
Anonymous user
2 years ago
Hello, Be careful, the code posted here is different than the one you use in the video. For instance Serial.print(RXdata, DEC); here and Serial.print(RXdata); in the video. Apart this, thanks for the tuto :)