Hallo, Ich hab ein kleines Taster Problem. Ich möchte 2 LED's unabhängig voneinander mittels 2 versch. tasten an und aus machen. Also taste 1 drücken Led1 = an und taste 1 nochmal drücken und Led1 aus. Das selbe mit Led 2 Nun hab ich das problem dass nur LED1 an und aus geht? Beide tasten sind entprellt und genau gleich verdrahtet auf m breadboard. LED ist auch richtig drinne.... Wenn jemand lust hat sich schnell meinen code anzusehen? Wäre echt lieb. Vielen Dank Randy
1 | #include <avr/io.h> |
2 | #include <util/delay.h> |
3 | #include <inttypes.h> |
4 | |
5 | #define LED_AN(LED) (PORTD |= (1<<(LED)))
|
6 | #define LED_AUS(LED) (PORTD &= ~(1<<(LED)))
|
7 | #define LED_TOGGLE(LED) (PORTD ^= (1<<(LED)))
|
8 | |
9 | #define LED1 PD0
|
10 | #define LED2 PD1
|
11 | |
12 | |
13 | // tester 1
|
14 | |
15 | #define TASTER1 PD2
|
16 | #define TASTER1_GEDRUECKT() (PIND & (1<<TASTER1))
|
17 | #define TASTE1_AUF 0
|
18 | #define TASTE1_ZU 1
|
19 | |
20 | // taster 2
|
21 | |
22 | #define TASTER2 PD3
|
23 | #define TASTER2_GEDRUECKT() (PIND & (1<<TASTER2))
|
24 | #define TASTE2_AUF 0
|
25 | #define TASTE2_ZU 1
|
26 | |
27 | |
28 | int main(void) |
29 | {
|
30 | uint8_t alter_tastenzustand1 = TASTE1_AUF; |
31 | uint8_t alter_tastenzustand2 = TASTE2_AUF; |
32 | DDRD &= ~(1<<TASTER1) | (1<<TASTER2); |
33 | DDRD |= (1<<LED1) | (1<<LED2); |
34 | |
35 | |
36 | while(1) |
37 | {
|
38 | |
39 | if (TASTER1_GEDRUECKT() && (alter_tastenzustand1 == TASTE1_AUF)) |
40 | {
|
41 | LED_TOGGLE(LED1); |
42 | |
43 | alter_tastenzustand1 = TASTE1_ZU; |
44 | }
|
45 | |
46 | if (!TASTER1_GEDRUECKT()) |
47 | alter_tastenzustand1 = TASTE1_AUF; |
48 | }
|
49 | |
50 | // led 2
|
51 | |
52 | if (TASTER2_GEDRUECKT() && (alter_tastenzustand2 == TASTE2_AUF)) |
53 | {
|
54 | |
55 | |
56 | LED_TOGGLE(LED2); |
57 | |
58 | alter_tastenzustand2 = TASTE2_ZU; |
59 | }
|
60 | |
61 | if (!TASTER2_GEDRUECKT()) |
62 | alter_tastenzustand2 = TASTE2_AUF; |
63 | |
64 | |
65 | |
66 | |
67 | }
|