Hi,
hoffe Ihr habt alle frohe Festtage !
Ich versuche gerade über den Seriellen Monitor in eine Switch-CASE zu
springen.
jedoch funktioniert das nicht ganz. Der Compiler meldet folgendes:
1 | sketch_dec26a:18:10: error: expected identifier before 'case'
|
2 |
|
3 | goto case 1;
|
4 |
|
5 | ^
|
6 |
|
7 | sketch_dec26a:18:10: error: expected ';' before 'case'
|
8 |
|
9 | sketch_dec26a:18:10: error: case label '1' not within a switch statement
|
10 |
|
11 | sketch_dec26a:18:16: error: expected ':' before ';' token
|
12 |
|
13 | goto case 1;
|
14 |
|
15 | ^
|
hier mein Code:
1 | byte Case = 1;
|
2 |
|
3 | unsigned long Millis;
|
4 |
|
5 | void setup() {
|
6 | Serial.begin(115200);
|
7 | Millis = millis();
|
8 |
|
9 | }
|
10 |
|
11 | void loop() {
|
12 |
|
13 | if (Serial.available() > 0) {
|
14 |
|
15 | const char a = Serial.read();
|
16 |
|
17 | if (a == '1') {
|
18 | goto case 1;
|
19 | }
|
20 | else if (a == '2') {}
|
21 | else if (a == '3') {}
|
22 | else if (a == '4') {}
|
23 | else if (a == '5') {}
|
24 | else if (a == '6') {}
|
25 |
|
26 | }
|
27 | }
|
28 |
|
29 | if (millis() - Millis >= 10000) {
|
30 | switch (Case) {
|
31 |
|
32 | case 1:
|
33 | Serial.println("Case 1");
|
34 |
|
35 | Case = 2;
|
36 | Millis = millis();
|
37 |
|
38 | break;
|
39 |
|
40 | case 2:
|
41 | Serial.println("Case 2");
|
42 |
|
43 | Case = 3;
|
44 | Millis = millis();
|
45 |
|
46 | break;
|
47 |
|
48 | case 3:
|
49 | Serial.println("Case 3");
|
50 |
|
51 | Case = 4;
|
52 | Millis = millis();
|
53 |
|
54 | break;
|
55 |
|
56 | case 4:
|
57 | Serial.println("Case 4");
|
58 |
|
59 | Case = 5;
|
60 | Millis = millis();
|
61 |
|
62 | break;
|
63 |
|
64 | case 5:
|
65 | Serial.println("Case 5");
|
66 |
|
67 | Case = 6;
|
68 | Millis = millis();
|
69 |
|
70 | break;
|
71 |
|
72 | case 6:
|
73 | Serial.println("Case 6");
|
74 |
|
75 | Case = 1;
|
76 | Millis = millis();
|
77 |
|
78 | break;
|
79 | }
|
80 | }
|
81 | }
|
Was mache ich falsch?
Mfg