Ben Michael
/
miniProject4
Servo that turns towards heat source with temperature reading display.
servo.cpp
- Committer:
- bmichael21
- Date:
- 2019-01-14
- Revision:
- 17:fc23cf904932
- Parent:
- 15:1eed07b5a5ba
File content as of revision 17:fc23cf904932:
#include "servo.h" #include "tempSnsr.h" PwmOut servo(p23); int curDutyCycle = 1500; //1500 corresponds to zero degrees with a change of 10 changing the value by one degree bool curDirection = 0; //the direction the servo moved last. the actual direction doesn't matter, we just continue or turn around void servoInit(){ servo.period(0.020);//the mandatory period for the servo servo.pulsewidth_us(curDutyCycle);//start the servo at zero degrees } void moveServo(){ if(curDiff < prevDiff) curDirection = !curDirection; //turn the other way- progress is being lost if(curDirection == 1 && curDutyCycle < 2400)//inputting numbers greater than 2400(90 degrees) or less than 600(-90 degrees) causes unpredictable behaviour curDutyCycle += 10; //+10 = +1 degree else if(curDirection == 0 && curDutyCycle > 600) curDutyCycle -= 10; servo.pulsewidth_us(curDutyCycle); }