Hallo
Ein Tiny (ein 13er z.B.) kann das natürlich locker ohne zusätzliche Bauteile. Ich konnte ja nicht ahnen, dass auch ein µC eingesetzt werden kann![]()
Drei Servos an einem Tiny13 in C (mit internem 1,2MHz-Defaulttakt):
(Code aus https://www.roboternetz.de/phpBB2/ze...=324867#324867)Code:#include <avr/io.h> #include <avr/interrupt.h> #define x_mitte 17 #define y_mitte 17 #define z_mitte 17 unsigned int x, y, z, demo; void delay(uint16_t d) // Warteschleife { uint16_t d1, dummy; for (d1=d; d1>0; d1--) dummy^=d1; } ISR(TIM0_COMPA_vect) // Servoansteuerung { static uint16_t count=0; if (count>x) PORTB &= ~(1<<PB0); else PORTB |= (1<<PB0); if (count>y) PORTB &= ~(1<<PB1); else PORTB |= (1<<PB1); if (count>z) PORTB &= ~(1<<PB2); else PORTB |= (1<<PB2); if (count < 200) count++; else count=0; } int main(void) { x=x_mitte; // Servos Basisposition y=y_mitte; z=z_mitte; demo=5; // 5 Einzelschritte DDRB = (1<<PB2) | (1<<PB1) | (1<<PB0); // Servoausgänge PORTB= (1<<PB3); // PullUp Taster ein TCCR0A = (0 << WGM00) | (1 << WGM01); // CTC-Mode TCCR0A |= (0 << COM0A0) | (0 << COM0A1); // ohne OCR-Pin TCCR0B = (0 << CS02) | (0 << CS01) | (1 << CS00); // no prescaler TIMSK0 = (1 << OCIE0A); // Interrupt ein OCR0A = 50; // nicht wissenschaltliche Frequenz sei(); while(1) { y=y_mitte+4; delay(400); // Schritt if (demo) while(PINB & (1<<PB3)); // warten auf Taste for (; x>x_mitte-12; x--) { if (x==5) y=y_mitte+7; if (x==0) y=y_mitte+5; if (x==-11) y=y_mitte+3; delay(120+x); } x=x_mitte-15; y=y_mitte+4; delay(100); y=y_mitte; delay(300); x=x_mitte+5; delay(1000); if (demo) demo--; } return(0); }
Gruß
mic







Zitieren

Lesezeichen