Last active
August 29, 2015 14:08
-
-
Save bowserthewizard/21d0925c48a1f7eaec2d to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//#include <Servo.h> | |
//Servo myservo; | |
int duty_cycle=0; | |
void setup() //This function executes only once | |
{ | |
// myservo.attach(3); | |
TCCR2B=(TCCR2B & 0xF8) | 0x07 ; | |
pinMode(3, OUTPUT); | |
} | |
void loop() // This function executes repeatedly | |
{ | |
while (1) { | |
readinput(); | |
delay(100); | |
servocontrol(); | |
} | |
} | |
int readinput() // This function executes repeatedly | |
{ | |
int addata = analogRead(0); | |
int a = .7; | |
int b = 2.4; | |
int freq = 30.52; | |
//now we want to take the input and map it to [a,b] for our pulse width | |
float scale = ((float)(b-a))/(1023-0); | |
return (scale*addata)*freq ; | |
} | |
void servocontrol() | |
{ | |
int duty_cycle = readinput(); | |
// myservo.write(pwm); | |
analogWrite(3, duty_cycle); | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment