Ben Michael
/
miniProject4
Servo that turns towards heat source with temperature reading display.
servo.cpp
- Committer:
- bmichael21
- Date:
- 2019-01-13
- Revision:
- 7:01f260a01953
- Parent:
- 1:596a2915f7a2
- Child:
- 8:fb50cf601521
File content as of revision 7:01f260a01953:
#include "servo.h" PwmOut servo(p21/*11111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111111*/); int curAngle = 1500; //1500 is zero degrees void servoInit(){ servo.period(0.020); servo.pulsewidth_us(servoAngleConvert(servoAngle));//start the servo at zero degrees } void moveServo(float tempDiff){ if(tempDiff > 0 && curAngle < 2400)//inputting numbers greater than 2400(90 degrees) or less than 600(-90 degrees) causes unpredictable behaviour curAngle++; //+1 = +0.1 degrees else if(tempDiff < 0 && curAngle > 600) curAngle--; servo.pulsewidth_us(curAngle); } //int servoAngle() { ////1500 is 0°. ////plus/minus one degree for every 10 //if (curAngle > 90 || curAngle < -90) { //return 1500; //prevents unpredictable behaviour of servo from out of bound input //} //return 1500 + (10 * x); //}