werty

Dependencies:   HCSR04 Servo mbed

Fork of catchCats by eunkyoung kim

Committer:
eunkyoungkim
Date:
Tue Sep 22 07:46:13 2015 +0000
Revision:
1:01d1c2c9ddb1
Parent:
0:7eded57f1445
Catch cats - Toy of cats ; WIZwiki7500, For Cats, UltraSonic, Servo motor,

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DavidMeza 0:7eded57f1445 1 #include "mbed.h"
eunkyoungkim 1:01d1c2c9ddb1 2 #include "stdlib.h" //For rand function
eunkyoungkim 1:01d1c2c9ddb1 3 #include "Servo.h"
DavidMeza 0:7eded57f1445 4 #include "HCSR04.h"
DavidMeza 0:7eded57f1445 5
eunkyoungkim 1:01d1c2c9ddb1 6 HCSR04 sensor(D11, D12); //(Trig Pin, Echo Pin)
eunkyoungkim 1:01d1c2c9ddb1 7 Servo myservo(D6);
DavidMeza 0:7eded57f1445 8
DavidMeza 0:7eded57f1445 9
DavidMeza 0:7eded57f1445 10 int main()
DavidMeza 0:7eded57f1445 11 {
eunkyoungkim 1:01d1c2c9ddb1 12
eunkyoungkim 1:01d1c2c9ddb1 13 int number = 0;
eunkyoungkim 1:01d1c2c9ddb1 14
DavidMeza 0:7eded57f1445 15 while(1){
eunkyoungkim 1:01d1c2c9ddb1 16 long d = sensor.distance(1);
eunkyoungkim 1:01d1c2c9ddb1 17 printf("d = %d\r\n",d);
eunkyoungkim 1:01d1c2c9ddb1 18 myservo = 0.5;
eunkyoungkim 1:01d1c2c9ddb1 19
eunkyoungkim 1:01d1c2c9ddb1 20 if(d<=20) //20cm
eunkyoungkim 1:01d1c2c9ddb1 21 {
eunkyoungkim 1:01d1c2c9ddb1 22 number = rand()%11; //0~10
eunkyoungkim 1:01d1c2c9ddb1 23 double a = number*0.1;
eunkyoungkim 1:01d1c2c9ddb1 24 printf("%d = %3f\r\n",number,a);
eunkyoungkim 1:01d1c2c9ddb1 25 myservo = number*0.1;
eunkyoungkim 1:01d1c2c9ddb1 26
eunkyoungkim 1:01d1c2c9ddb1 27 }
eunkyoungkim 1:01d1c2c9ddb1 28 wait(0.2);
eunkyoungkim 1:01d1c2c9ddb1 29 }
eunkyoungkim 1:01d1c2c9ddb1 30 }
eunkyoungkim 1:01d1c2c9ddb1 31
eunkyoungkim 1:01d1c2c9ddb1 32
DavidMeza 0:7eded57f1445 33
DavidMeza 0:7eded57f1445 34
DavidMeza 0:7eded57f1445 35