werty

Dependencies:   HCSR04 Servo mbed

Fork of catchCats by eunkyoung kim

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "stdlib.h"  //For rand function 
00003 #include "Servo.h"   
00004 #include "HCSR04.h"
00005 
00006 HCSR04 sensor(D11, D12); //(Trig Pin, Echo Pin)
00007 Servo myservo(D6);
00008 
00009 
00010 int main()
00011 {
00012   
00013     int number = 0;
00014     
00015     while(1){
00016         long d = sensor.distance(1);
00017         printf("d = %d\r\n",d);    
00018         myservo = 0.5;  
00019 
00020        if(d<=20)    //20cm
00021         {
00022                 number = rand()%11;  //0~10
00023                 double a = number*0.1;
00024                 printf("%d = %3f\r\n",number,a);                 
00025                 myservo = number*0.1;
00026           
00027         }      
00028         wait(0.2); 
00029     }
00030 }
00031             
00032             
00033                 
00034                 
00035