A50Hztimerinterrupttorefreshaservoandtheubiquitousscanleft/rightcodeonanarduinouno.
; A uno servo controller that refreshes the servo every 20ms; servopos is the servo position
#chipmega328p,16
#configosc=int
#optionExplicit;dimcountasworddimservoposasworddimservodirasbyte
#defineservopinportb.0;uno pin 8servopos=1500;usservodir=1dirservopinout;TCCR1A=0x80;TCCR1B=0x0A;OCR1AH=0x9c;OCR1AL=0x3f;OnInterruptTimer1Match1callISR;main programdo;ifservodir=1thenservopos=servopos+80;usifservopos=2220then;end of servo turnservodir=0endifelseservopos=servopos-80;usifservopos=780then;end of servo turnservodir=1endifendif;wait1sloop;end main programsubISRpulseoutservopin,servoposusendsub
If you would like to refer to this comment somewhere else in this project, copy and paste the following link: