Final

Dependencies:   mbed

Fork of MiniProject5_LightTracker by Austin Sloop

main.cpp

Committer:
pstephens18
Date:
2016-01-12
Revision:
13:871d01d0d250
Parent:
12:7bc0afbc651a
Child:
14:69cad6d9a2e5

File content as of revision 13:871d01d0d250:

/*Project to make a servo aim to perpendicular photoresistors at a light source, and display the angle of the source to the servo
 Project and code by Preston Stephens and Austin Sloop, Inspired by Dr. Larkin.   1/11/16
*/

#include "mbed.h"
#include "SegDisplay.h"
#include "ServoControl.h"

AnalogIn sensor1(p19);
AnalogIn sensor2(p20);
Serial pc(USBTX, USBRX);
float val1, val2;

int angle;

int main(){
    SegInit();
    ServoInit();
    angle=0;
while(1)
{
    val1 = sensor1;
    val2 = sensor2;
    pc.printf("%.2f \t %.2f\n\r", val1, val2);
    if((val1+0.01)<val2){angle=angle+5;}
    if(val1>(val2+0.01)){angle=angle-5;}
    ServoControl(angle);
    SegDisplay(angle);
}
}