- קוד: בחר הכל
int main(void)
{
// Make sure all our registers are clear
DDRB = 0;
DDRC = 0;
DDRD = 0;
// Make sure all our pull-up resistors are clear
PORTB = 0;
PORTC = 0;
PORTD = 0;
// Initialize the timer0 PWM system:
pwm0_init();
// Motors are stopped when we initialize them, so there's
// no need to do that after the init routine.
// Make sure PB5 is an input (bump left)
DDRB &= ~(1 << PB3);
//pull up rezistor
PORTB |= (1 << PB3);
unsigned int encoderB;
// The endless loop
for(;;)
{
if (((PINB & (1 << PB3)) == 0))
{
encoderB += 1;
}
if (encoderB == 3)
{
pwm0_a(0);
pwm0_b(0);
break;
}
else
{
// Both motors forward
pwm0_a(115);
pwm0_b(115);
//delay_sec(1);
}
}
// We never get here, but return a zero if we ever do.
return(0);
}
ארבל
דרך אגב, כרגע, כל פעם שהחיישן מופעל, המנועים עוצרים, ולא רק אחרי הפעם השלישית. וכאשר החיישן כבר לא מופעל, המנועים ממשיכים לעבוד. המטרה שלי היא שכאשר החיישן יופעל 3 פעמים. המנועים יעצרו ולא ימשיכו.




