Catch cats - Toy of cats

Dependencies:   HCSR04 Servo mbed

Fork of Ultrasonic by David Meza

main.cpp

Committer:
eunkyoungkim
Date:
2015-09-22
Revision:
1:01d1c2c9ddb1
Parent:
0:7eded57f1445

File content as of revision 1:01d1c2c9ddb1:

#include "mbed.h"
#include "stdlib.h"  //For rand function 
#include "Servo.h"   
#include "HCSR04.h"

HCSR04 sensor(D11, D12); //(Trig Pin, Echo Pin)
Servo myservo(D6);


int main()
{
  
    int number = 0;
    
    while(1){
        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); 
    }
}