/*********************************** * (C) 2007-2008 by Tomasz bla Fortuna . * License: GPL3+ (See Docs/LICENSE) * * Motor Encoder ********************/ namespace Encoder { #define ENCODER_DDR DDRB #define ENCODER_PIN PINB #define ENCODER_PORT PORTB #define ENCODER_L (1< ILim) ITmp = ILim; Answer = 2 * (PTmp + ITmp + DTmp); Answer /= 10; // Direct motors if (Answer < 0) Motor::Dir(Motor::Both, Dir::Left); else Motor::Dir(Motor::Both, Dir::Right); /* ABS */ if (Answer < 0) Tmp = - Answer; else Tmp = Answer; const UChar Base = 0; if (Tmp > 255 - Base) Power = 255; else Power = Base + Tmp; Motor::Speed(Motor::Both, Power); /* Only for display */ if (Answer < 0) Power_Display = -Power; else Power_Display = Power; } } #endif static inline Void Init(void) { /* Connect encoder to pins PB0, PB1; * Pin Change Interrupt 1 - PCI1, PCMSK1 covers this. */ /* Enable inputs with pull-ups */ ENCODER_PORT |= ENCODER_LP; ENCODER_DDR &= (UChar)(~ENCODER_LP); EICRA = (1<