Hallo zusammen,
ich habe eine kleine Frage zu meinem C-Programm:
Ich bewege einen Cursor über 5 Zahlen, um eine Schnell einzustellen
(also zB 10k-Stelle auf 3, 1k-Stelle auf 2 -> 32000).
Dazu habe ich 5 bytes a-e, alle anfangs gleich 0.
Wenn ich nun a inkrementiere, inkrementiert sich auch b-e,
Wenn ich b inkrementiere, inkrementiert sich auch c-e,
usw.
Wenn ich e inkrementiere, inkrementiert sich e.
Randinfo:
Button(x) gibt true zurück, wenn Button x gedrück (Abfrage von
Widerstandsarray). lastpress ist ein kleiner Helfer zum Entprellen.
mein Code:
1 |
|
2 | if(Button(3)) {
|
3 | lastpress = millis();
|
4 | switch (cursor) {
|
5 | case 0:
|
6 | a++;
|
7 | if(a>9) a = 0;
|
8 | case 1:
|
9 | b++;
|
10 | if(b>9) b = 0;
|
11 | case 2:
|
12 | c++;
|
13 | if(c>9) c = 0;
|
14 | case 3:
|
15 | d++;
|
16 | if(d>9) d = 0;
|
17 | case 4:
|
18 | e++;
|
19 | if(e>9) e = 0;
|
20 | }
|
21 | aktuell = 0;
|
22 | }
|
In der umschließenden While-Scheife passiert nicht viel:
1 | while(1) //Auf Tastendruck Warten
|
2 | {
|
3 | if(aktuell == 0) { //Wenn nicht aktuell
|
4 |
|
5 | /* Ausgabe */
|
6 |
|
7 | aktuell = 1;
|
8 | lcd.setCursor(7+cursor,0);
|
9 | }
|
10 | if(Button(5)) { //Cursor nach rechts
|
11 | lastpress = millis();
|
12 | cursor++;
|
13 | cursor = cursor % 5;
|
14 | aktuell = 0;
|
15 | }
|
16 | if(Button(2)) { //Cursor nach links
|
17 | lastpress = millis();
|
18 | cursor--;
|
19 | if(cursor > 4) cursor = 4;
|
20 | aktuell = 0;
|
21 | }
|
22 | if(Button(3)) { //inkrementieren
|
23 | lastpress = millis();
|
24 | switch (cursor) {
|
25 | case 0:
|
26 | a++;
|
27 | if(a>9) a = 0;
|
28 | case 1:
|
29 | b++;
|
30 | if(b>9) b = 0;
|
31 | case 2:
|
32 | c++;
|
33 | if(c>9) c = 0;
|
34 | case 3:
|
35 | d++;
|
36 | if(d>9) d = 0;
|
37 | case 4:
|
38 | e++;
|
39 | if(e>9) e = 0;
|
40 | }
|
41 | aktuell = 0;
|
42 | }
|
43 | }
|
Sieht jemand meinen Fehler? Ich rauf mir hier die Haare :D
Danke, Olli