werty
Dependencies: HCSR04 Servo mbed
Fork of catchCats by
Revision 1:01d1c2c9ddb1, committed 2015-09-22
- Comitter:
- eunkyoungkim
- Date:
- Tue Sep 22 07:46:13 2015 +0000
- Parent:
- 0:7eded57f1445
- Commit message:
- Catch cats - Toy of cats ; WIZwiki7500, For Cats, UltraSonic, Servo motor,
Changed in this revision
diff -r 7eded57f1445 -r 01d1c2c9ddb1 LCD40x2.lib --- a/LCD40x2.lib Wed Sep 04 14:32:43 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/wertyfrog/code/LCD40x2/#ca430b27054d
diff -r 7eded57f1445 -r 01d1c2c9ddb1 Servo.lib --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/Servo.lib Tue Sep 22 07:46:13 2015 +0000 @@ -0,0 +1,1 @@ +https://developer.mbed.org/users/eunkyoungkim/code/Servo/#9188280ec20c
diff -r 7eded57f1445 -r 01d1c2c9ddb1 USBDevice.lib --- a/USBDevice.lib Wed Sep 04 14:32:43 2013 +0000 +++ /dev/null Thu Jan 01 00:00:00 1970 +0000 @@ -1,1 +0,0 @@ -http://mbed.org/users/mbed_official/code/USBDevice/#6030a12b6c62
diff -r 7eded57f1445 -r 01d1c2c9ddb1 main.cpp --- a/main.cpp Wed Sep 04 14:32:43 2013 +0000 +++ b/main.cpp Tue Sep 22 07:46:13 2015 +0000 @@ -1,44 +1,35 @@ #include "mbed.h" +#include "stdlib.h" //For rand function +#include "Servo.h" #include "HCSR04.h" -#include "LCD40x2.h" -DigitalOut led(LED_RED); -DigitalOut led2(LED_GREEN); - -HCSR04 sensor(PTA12, PTD4); - -TextLCD lcd(PTC12, PTC16, PTC13, PTC11, PTC10, PTC6, PTC5); -//TextLCD(PinName rs, PinName rw, PinName e, PinName d0, PinName d1, PinName d2, PinName d3, LCDType type = LCD16x2); +HCSR04 sensor(D11, D12); //(Trig Pin, Echo Pin) +Servo myservo(D6); int main() { + + int number = 0; + while(1){ - long d = sensor.distance(1); - lcd.printf("Distance:%d ",sensor.distance(1)); - - if(d<=10) - { - led = 0; - led2 = 1; - } - - if(d>=200) - { - led2 = 0; - led = 1; - } - if(d>=11 && d<=39) - { - led2 = 0; - led=0; - } - - - } - } - - + long d = sensor.distance(1); + printf("d = %d\r\n",d); + myservo = 0.5; + + if(d<=20) //20cm + { + number = rand()%11; //0~10 + double a = number*0.1; + printf("%d = %3f\r\n",number,a); + myservo = number*0.1; + + } + wait(0.2); + } +} + + \ No newline at end of file
diff -r 7eded57f1445 -r 01d1c2c9ddb1 mbed.bld --- a/mbed.bld Wed Sep 04 14:32:43 2013 +0000 +++ b/mbed.bld Tue Sep 22 07:46:13 2015 +0000 @@ -1,1 +1,1 @@ -http://mbed.org/users/mbed_official/code/mbed/builds/9c8f0e3462fb \ No newline at end of file +http://mbed.org/users/mbed_official/code/mbed/builds/4f6c30876dfa \ No newline at end of file