werty

Dependencies:   HCSR04 Servo mbed

Fork of catchCats by eunkyoung kim

Committer:
DavidMeza
Date:
Wed Sep 04 14:32:43 2013 +0000
Revision:
0:7eded57f1445
Child:
1:01d1c2c9ddb1
ultrasonic code conti

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DavidMeza 0:7eded57f1445 1 #include "mbed.h"
DavidMeza 0:7eded57f1445 2 #include "HCSR04.h"
DavidMeza 0:7eded57f1445 3 #include "LCD40x2.h"
DavidMeza 0:7eded57f1445 4
DavidMeza 0:7eded57f1445 5 DigitalOut led(LED_RED);
DavidMeza 0:7eded57f1445 6 DigitalOut led2(LED_GREEN);
DavidMeza 0:7eded57f1445 7
DavidMeza 0:7eded57f1445 8 HCSR04 sensor(PTA12, PTD4);
DavidMeza 0:7eded57f1445 9
DavidMeza 0:7eded57f1445 10 TextLCD lcd(PTC12, PTC16, PTC13, PTC11, PTC10, PTC6, PTC5);
DavidMeza 0:7eded57f1445 11 //TextLCD(PinName rs, PinName rw, PinName e, PinName d0, PinName d1, PinName d2, PinName d3, LCDType type = LCD16x2);
DavidMeza 0:7eded57f1445 12
DavidMeza 0:7eded57f1445 13
DavidMeza 0:7eded57f1445 14 int main()
DavidMeza 0:7eded57f1445 15 {
DavidMeza 0:7eded57f1445 16 while(1){
DavidMeza 0:7eded57f1445 17 long d = sensor.distance(1);
DavidMeza 0:7eded57f1445 18 lcd.printf("Distance:%d ",sensor.distance(1));
DavidMeza 0:7eded57f1445 19
DavidMeza 0:7eded57f1445 20 if(d<=10)
DavidMeza 0:7eded57f1445 21 {
DavidMeza 0:7eded57f1445 22 led = 0;
DavidMeza 0:7eded57f1445 23 led2 = 1;
DavidMeza 0:7eded57f1445 24 }
DavidMeza 0:7eded57f1445 25
DavidMeza 0:7eded57f1445 26 if(d>=200)
DavidMeza 0:7eded57f1445 27 {
DavidMeza 0:7eded57f1445 28 led2 = 0;
DavidMeza 0:7eded57f1445 29 led = 1;
DavidMeza 0:7eded57f1445 30 }
DavidMeza 0:7eded57f1445 31 if(d>=11 && d<=39)
DavidMeza 0:7eded57f1445 32 {
DavidMeza 0:7eded57f1445 33 led2 = 0;
DavidMeza 0:7eded57f1445 34 led=0;
DavidMeza 0:7eded57f1445 35 }
DavidMeza 0:7eded57f1445 36
DavidMeza 0:7eded57f1445 37
DavidMeza 0:7eded57f1445 38 }
DavidMeza 0:7eded57f1445 39 }
DavidMeza 0:7eded57f1445 40
DavidMeza 0:7eded57f1445 41
DavidMeza 0:7eded57f1445 42
DavidMeza 0:7eded57f1445 43
DavidMeza 0:7eded57f1445 44