Originariamente inviato da biv2533
Visualizza il messaggio

#ifdef TRI void initializeServo() { pinMode(3,OUTPUT); TCCR0A = 0; // normal counting mode TIMSK0 |= (1<<OCIE0A); // Enable CTC interrupt } ISR(TIMER0_COMPA_vect) { static uint8_t state = 0; static uint8_t count; if (state == 0) { PORTD |= 1<<3; // this is 25 time faster than DigitalWrite ! coded for Digital Pin 3 only OCR0A+= 250; // 1000 us state++ ; } else if (state == 1) { OCR0A+= ServoYaw; // 1000 + [0-1020] us state++; } else if (state == 2) { PORTD &= ~(1<<3); count = 16; // 18 x 1020 us state++; OCR0A+= 255; // 1020 us } else if (state == 3) { if (count > 0) count--; else state = 0; OCR0A+= 255; } } #endif
Commenta