Preston Stephens / Mbed 2 deprecated MiniProject5_LightTracker

Dependencies:   mbed

Fork of MiniProject5_LightTracker by Austin Sloop

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 /*Project to make a servo aim to perpendicular photoresistors at a light source, and display the angle of the source to the servo
00002  Project and code by Preston Stephens and Austin Sloop, Inspired by Dr. Larkin.   1/11/16
00003 */
00004 
00005 #include "mbed.h"
00006 #include "SegDisplay.h"
00007 #include "ServoControl.h"
00008 
00009 AnalogIn sensor1(p19);
00010 AnalogIn sensor2(p20);
00011 Serial pc(USBTX, USBRX);
00012 float val1, val2;
00013 
00014 int angle;
00015 
00016 int main(){
00017     SegInit();
00018     ServoInit();
00019     angle=0;
00020 while(1)
00021 {
00022     val1 = sensor1;
00023     val2 = sensor2;
00024     pc.printf("%.2f \t %.2f\n\r", val1, val2);
00025     if((val1+0.03)>val2){angle=angle+1;}
00026     if(val1<(val2+0.03)){angle=angle-1;}
00027     angle=ServoControl(angle);
00028     SegDisplay(angle);
00029 }
00030 }
00031