part 6 and extra credit

Dependencies:   C12832 Servo mbed

Committer:
jaredwil
Date:
Tue Mar 03 23:04:41 2015 +0000
Revision:
3:853bc68793d0
Parent:
2:1d960bbbb0fe
Child:
4:9c354b69b590
**

Who changed what in which revision?

UserRevisionLine numberNew contents of line
jaredwil 0:ba4c01e9484b 1 #include "mbed.h"
jaredwil 0:ba4c01e9484b 2 #include "C12832.h"
jaredwil 0:ba4c01e9484b 3 #include "Servo.h"
jaredwil 0:ba4c01e9484b 4
jaredwil 0:ba4c01e9484b 5
jaredwil 0:ba4c01e9484b 6 Servo s1(p21);
jaredwil 0:ba4c01e9484b 7
jaredwil 0:ba4c01e9484b 8 C12832 lcd(p5, p7, p6, p8, p11);
jaredwil 0:ba4c01e9484b 9
jaredwil 0:ba4c01e9484b 10 DigitalOut myled(LED1);
jaredwil 0:ba4c01e9484b 11 AnalogIn light(p16);
jaredwil 0:ba4c01e9484b 12
jaredwil 0:ba4c01e9484b 13 int main() {
jaredwil 0:ba4c01e9484b 14
jaredwil 0:ba4c01e9484b 15 float val,val2, count = 0;
jaredwil 0:ba4c01e9484b 16
jaredwil 1:016e2bcda058 17 //Flash Phone Flash 4 times at close range to start the servo
jaredwil 1:016e2bcda058 18
jaredwil 0:ba4c01e9484b 19 while(count < 4){
jaredwil 0:ba4c01e9484b 20 val = light.read();
jaredwil 0:ba4c01e9484b 21 if(val<0.5){
jaredwil 2:1d960bbbb0fe 22 lcd.locate(0,3);
jaredwil 2:1d960bbbb0fe 23 lcd.printf("reading: %.3f", val);
jaredwil 0:ba4c01e9484b 24 wait(0.1);
jaredwil 0:ba4c01e9484b 25 count++;
jaredwil 0:ba4c01e9484b 26 while(light.read() < 0.5);
jaredwil 3:853bc68793d0 27 lcd.cls();
jaredwil 0:ba4c01e9484b 28 }
jaredwil 0:ba4c01e9484b 29
jaredwil 0:ba4c01e9484b 30 }
jaredwil 1:016e2bcda058 31
jaredwil 0:ba4c01e9484b 32 while(1) {
jaredwil 1:016e2bcda058 33 lcd.cls();
jaredwil 1:016e2bcda058 34 val = light.read();
jaredwil 2:1d960bbbb0fe 35
jaredwil 1:016e2bcda058 36 val2 = 1-val;
jaredwil 1:016e2bcda058 37
jaredwil 1:016e2bcda058 38 //even for little light start servo with small steps(low speed)
jaredwil 1:016e2bcda058 39 if(val2 > 0.1) {
jaredwil 2:1d960bbbb0fe 40 lcd.locate(0,3);
jaredwil 2:1d960bbbb0fe 41 lcd.printf("Sensor reading: %.3f", val);
jaredwil 1:016e2bcda058 42 for(float p=0; p<1.0; p += val2) {
jaredwil 1:016e2bcda058 43 s1 = p;
jaredwil 1:016e2bcda058 44 wait(0.2);
jaredwil 1:016e2bcda058 45 }
jaredwil 1:016e2bcda058 46 for(float p=1.0; p>0; p -= val2) {
jaredwil 1:016e2bcda058 47 s1 = p;
jaredwil 1:016e2bcda058 48 wait(0.2);
jaredwil 1:016e2bcda058 49 }
jaredwil 1:016e2bcda058 50 }
jaredwil 0:ba4c01e9484b 51 }
jaredwil 0:ba4c01e9484b 52 }