// 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; } }