Skip to content

Instantly share code, notes, and snippets.

@RaspPiGuy
Created March 9, 2014 19:04
#include <avr/io.h>
#include <InputNumbFromTerminal.h>
TERMNUMB inFromTerm;
void setup(){
Serial.begin(9600);
//Setting Up WGM, COM amd prescaler bits per above comments
TCCR1A = 0b10000000;
TCCR1B = 0b00010010;
ICR1 = 15000; // 20ms. Cycle Time
OCR1A = 1125; // 1.5 ms. Initial Pulse Width to center servo
DDRB |= (1 << PB1); // Output on PB1
}
void loop(){
float angle;
int pwm_count;
float msec;
Serial.print("Input angle in degrees -90.0 to 90.0: ");
angle = inFromTerm.termNumb();
Serial.println("");
if (angle >= -90.0 && angle <= 90.0){
msec = float(angle)/90.0 + 1.5;
pwm_count = 750.0 * msec;
OCR1A = pwm_count;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment