Hallo Zusammen, ich bin gerade dabei eine LED mit ein Taster ein- und auszuschalten. Dazu habe ich folgendes geschrieben, allerdings kriege ich den Schalter nicht entprellt. Was mache ich hier falsch oder was habe ich hier nicht berücksichtigt. (Ich bin noch etwas unerfahren in uC Programmierung)
1 | int main(void) |
2 | {
|
3 | unsigned char buttonPress; |
4 | unsigned char buttonRelease; |
5 | unsigned int count; |
6 | |
7 | DDRB = ((1<<DDB0)|(1<<DDB1)); |
8 | PORTB = ((1<<PB0)|(1<<PB1)); |
9 | |
10 | while(1) |
11 | {
|
12 | if(PINB & (1<<PB2)) |
13 | {
|
14 | count++; |
15 | }
|
16 | |
17 | if((count>=2)&&(count<=20)) |
18 | {
|
19 | buttonPress=1; |
20 | count=0; |
21 | }
|
22 | |
23 | else
|
24 | {
|
25 | buttonPress=0; |
26 | }
|
27 | |
28 | |
29 | if(!(PINB &(1<<PB2))) |
30 | {
|
31 | buttonRelease=1; |
32 | }
|
33 | |
34 | |
35 | if(buttonPress==1) |
36 | {
|
37 | PORTB=(1<<PB0); |
38 | }
|
39 | |
40 | if(buttonRelease==1) |
41 | {
|
42 | if(buttonPress==1) |
43 | {
|
44 | PORTB=(0<<PB0); |
45 | buttonRelease=0; |
46 | }
|
47 | }
|
48 | |
49 | }
|
50 | }
|
vielen Dank