Maar waarom zou je een Attiny gebruiken voor servo's?
#ifdef USE_TIMER0 //reset the Timer Counter Control Register to its reset value TCCR0B = 0; #if F_CPU == 8000000L //set counter0 prescaler to 64 //our FCLK is 8mhz so this makes each timer tick be 8 microseconds long TCCR0B &= ~(1<< CS02); //clear TCCR0B |= (1<< CS01); //set TCCR0B |= (1<< CS00); //set #elif F_CPU == 1000000L //set counter0 prescaler to 8 //our F_CPU is 1mhz so this makes each timer tick be 8 microseconds long TCCR0B &= ~(1<< CS02); //clear TCCR0B |= (1<< CS01); //set TCCR0B &= ~(1<< CS00); //clear #else //unsupported clock speed //TODO: find a way to have the compiler stop compiling and bark at the user #endif #endif #ifdef USE_TIMER1 //reset the Timer Counter Control Register to its reset value TCCR1 = 0; #if F_CPU == 8000000L //set counter1 prescaler to 64 //our F_CPU is 8mhz so this makes each timer tick be 8 microseconds long TCCR1 &= ~(1<< CS13); //clear TCCR1 |= (1<< CS12); //set TCCR1 |= (1<< CS11); //set TCCR1 |= (1<< CS10); //set #elif F_CPU == 1000000L //set counter1 prescaler to 8 //our F_CPU is 1mhz so this makes each timer tick be 8 microseconds long TCCR1 &= ~(1<< CS13); //clear TCCR1 |= (1<< CS12); //set TCCR1 &= ~(1<< CS11); //clear TCCR1 &= ~(1<< CS10); //clear #else //unsupported clock speed //TODO: find a way to have the compiler stop compiling and bark at the user #endif
#error Clock speed unsupported
void delayMicroseconds(uint16_t us){#if F_CPU >= 16000000L // for the 16 MHz clock on most Arduino boards // for a one-microsecond delay, simply return. the overhead // of the function call yields a delay of approximately 1 1/8 us.