Final

Dependencies:   mbed

Fork of MiniProject5_LightTracker by Austin Sloop

Committer:
asloop18
Date:
Tue Jan 12 01:41:19 2016 +0000
Revision:
14:69cad6d9a2e5
Parent:
13:871d01d0d250
Mission Accomplished; ; Working Version

Who changed what in which revision?

UserRevisionLine numberNew contents of line
asloop18 12:7bc0afbc651a 1 /*Project to make a servo aim to perpendicular photoresistors at a light source, and display the angle of the source to the servo
asloop18 12:7bc0afbc651a 2 Project and code by Preston Stephens and Austin Sloop, Inspired by Dr. Larkin. 1/11/16
asloop18 12:7bc0afbc651a 3 */
asloop18 0:68508074b5d5 4
asloop18 0:68508074b5d5 5 #include "mbed.h"
pstephens18 1:8e14c2404f45 6 #include "SegDisplay.h"
asloop18 8:96b30706335b 7 #include "ServoControl.h"
asloop18 0:68508074b5d5 8
asloop18 10:b7cebc1f3768 9 AnalogIn sensor1(p19);
asloop18 10:b7cebc1f3768 10 AnalogIn sensor2(p20);
pstephens18 13:871d01d0d250 11 Serial pc(USBTX, USBRX);
pstephens18 13:871d01d0d250 12 float val1, val2;
asloop18 10:b7cebc1f3768 13
pstephens18 13:871d01d0d250 14 int angle;
asloop18 9:daeae936f9ec 15
asloop18 2:d50d55831d50 16 int main(){
pstephens18 11:7b3d64a66efd 17 SegInit();
pstephens18 11:7b3d64a66efd 18 ServoInit();
pstephens18 13:871d01d0d250 19 angle=0;
pstephens18 13:871d01d0d250 20 while(1)
pstephens18 13:871d01d0d250 21 {
pstephens18 13:871d01d0d250 22 val1 = sensor1;
pstephens18 13:871d01d0d250 23 val2 = sensor2;
pstephens18 13:871d01d0d250 24 pc.printf("%.2f \t %.2f\n\r", val1, val2);
asloop18 14:69cad6d9a2e5 25 if((val1+0.03)>val2){angle=angle+1;}
asloop18 14:69cad6d9a2e5 26 if(val1<(val2+0.03)){angle=angle-1;}
asloop18 14:69cad6d9a2e5 27 angle=ServoControl(angle);
pstephens18 13:871d01d0d250 28 SegDisplay(angle);
pstephens18 13:871d01d0d250 29 }
pstephens18 11:7b3d64a66efd 30 }
asloop18 10:b7cebc1f3768 31