You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
815 B
50 lines
815 B
|
13 years ago
|
|
||
|
|
// alter drehimpulsgebercode, aus marcus-thermometer
|
||
|
|
void buttonpoll(){ // runs with 1.2kHz
|
||
|
|
uint8_t l,r,t,flanks,dir;
|
||
|
|
l=BUTTPIN & _BV(BUTTLPIN);
|
||
|
|
r=BUTTPIN & _BV(BUTTRPIN);
|
||
|
|
t=BUTTPIN & _BV(BUTTTPIN);
|
||
|
|
|
||
|
|
// debounce code
|
||
|
|
if (t != butttold && !butttbounce ) {
|
||
|
|
butttold = t;
|
||
|
|
butttbounce = BUTT_BOUNCE;
|
||
|
|
if (t == 0) { // active low
|
||
|
|
buttonevent |= BUTTEV_PUSH;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
flanks=0;
|
||
|
|
dir=0;
|
||
|
|
if (l != buttlold) {
|
||
|
|
flanks += 1;
|
||
|
|
}
|
||
|
|
if (r != buttrold) {
|
||
|
|
flanks += 1;
|
||
|
|
dir = 1;
|
||
|
|
}
|
||
|
|
if (flanks == 1){ // we need to have exactly one flank, 0 flanks are no
|
||
|
|
// change, and 2 flanks are too fast (error)
|
||
|
|
if (l) {
|
||
|
|
dir ^= 1;
|
||
|
|
}
|
||
|
|
if (r) {
|
||
|
|
dir ^= 1;
|
||
|
|
}
|
||
|
|
if ((r && l) || (!r && !l)) {
|
||
|
|
buttoninc += dir ? -1 : 1;
|
||
|
|
}
|
||
|
|
}
|
||
|
|
|
||
|
|
buttlold = l;
|
||
|
|
buttrold = r;
|
||
|
|
|
||
|
|
|
||
|
|
if(butttbounce){
|
||
|
|
butttbounce -= 1;
|
||
|
|
}
|
||
|
|
|
||
|
|
}
|
||
|
|
|