el archivo cambio, la libreria del servo es distinta

Dependencies:   Servo

Committer:
intersect20
Date:
Wed Nov 18 17:00:44 2020 +0000
Revision:
1:5b8b3a6e9f8c
Parent:
0:24034ea3555d
proyecto Radar;

Who changed what in which revision?

UserRevisionLine numberNew contents of line
DAVIID222 0:24034ea3555d 1 #include "mbed.h"
DAVIID222 0:24034ea3555d 2 #include "rtos.h"
DAVIID222 0:24034ea3555d 3 #include "Servo.h"
DAVIID222 0:24034ea3555d 4
intersect20 1:5b8b3a6e9f8c 5 Serial pc(USBTX, USBRX);
intersect20 1:5b8b3a6e9f8c 6
DAVIID222 0:24034ea3555d 7 DigitalOut trig(D3);
DAVIID222 0:24034ea3555d 8 DigitalIn echo(D2);
DAVIID222 0:24034ea3555d 9 Servo myservo(D4);
DAVIID222 0:24034ea3555d 10
DAVIID222 0:24034ea3555d 11 Thread hilo_tarea1;
DAVIID222 0:24034ea3555d 12 Thread hilo_tarea2;
DAVIID222 0:24034ea3555d 13 Timer senal;
DAVIID222 0:24034ea3555d 14 float distancia;
intersect20 1:5b8b3a6e9f8c 15 float angle;
DAVIID222 0:24034ea3555d 16 void tarea1(void);
DAVIID222 0:24034ea3555d 17 void tarea2(void);
DAVIID222 0:24034ea3555d 18
DAVIID222 0:24034ea3555d 19 int main()
DAVIID222 0:24034ea3555d 20 {
intersect20 1:5b8b3a6e9f8c 21
DAVIID222 0:24034ea3555d 22 hilo_tarea1.start(tarea1);
DAVIID222 0:24034ea3555d 23 hilo_tarea2.start(tarea2);
DAVIID222 0:24034ea3555d 24 hilo_tarea1.set_priority(osPriorityNormal);
DAVIID222 0:24034ea3555d 25 while (true) {
intersect20 1:5b8b3a6e9f8c 26
DAVIID222 0:24034ea3555d 27 }
DAVIID222 0:24034ea3555d 28 }
DAVIID222 0:24034ea3555d 29
intersect20 1:5b8b3a6e9f8c 30 void tarea1(void)
intersect20 1:5b8b3a6e9f8c 31 {
intersect20 1:5b8b3a6e9f8c 32 while(true) {
DAVIID222 0:24034ea3555d 33 senal.reset();
DAVIID222 0:24034ea3555d 34 trig = 0;
DAVIID222 0:24034ea3555d 35 wait_us(2);
DAVIID222 0:24034ea3555d 36 trig = 1;
DAVIID222 0:24034ea3555d 37 wait_us(10);
DAVIID222 0:24034ea3555d 38 trig = 0;
DAVIID222 0:24034ea3555d 39 while(echo==0);
DAVIID222 0:24034ea3555d 40 senal.start();
DAVIID222 0:24034ea3555d 41 while(echo==1);
DAVIID222 0:24034ea3555d 42 senal.stop();
DAVIID222 0:24034ea3555d 43 distancia = (senal.read_us())/58;
intersect20 1:5b8b3a6e9f8c 44 pc.printf("%.f;%.f\n\r",angle,distancia);
DAVIID222 0:24034ea3555d 45 ThisThread::sleep_for(50);
DAVIID222 0:24034ea3555d 46 }
DAVIID222 0:24034ea3555d 47 }
DAVIID222 0:24034ea3555d 48
intersect20 1:5b8b3a6e9f8c 49 void tarea2(void)
intersect20 1:5b8b3a6e9f8c 50 {
intersect20 1:5b8b3a6e9f8c 51 float range = 0.0009;
intersect20 1:5b8b3a6e9f8c 52 bool direction = true;
intersect20 1:5b8b3a6e9f8c 53 float position = 0.0;
intersect20 1:5b8b3a6e9f8c 54 myservo.calibrate(range, 45.0);
intersect20 1:5b8b3a6e9f8c 55 while(true) {
intersect20 1:5b8b3a6e9f8c 56 if(direction) {
intersect20 1:5b8b3a6e9f8c 57 for (int i=-90; i< 90; i++) {
intersect20 1:5b8b3a6e9f8c 58 angle= i+90;
intersect20 1:5b8b3a6e9f8c 59 myservo.position(i);
intersect20 1:5b8b3a6e9f8c 60 wait_ms(17);
intersect20 1:5b8b3a6e9f8c 61 }
intersect20 1:5b8b3a6e9f8c 62 direction=false;
intersect20 1:5b8b3a6e9f8c 63 } else {
intersect20 1:5b8b3a6e9f8c 64 for (int i=90; i> -90; i--) {
intersect20 1:5b8b3a6e9f8c 65 angle = i+90;
intersect20 1:5b8b3a6e9f8c 66 myservo.position(i);
intersect20 1:5b8b3a6e9f8c 67 wait_ms(17);
intersect20 1:5b8b3a6e9f8c 68 }
intersect20 1:5b8b3a6e9f8c 69 direction=true;
intersect20 1:5b8b3a6e9f8c 70
DAVIID222 0:24034ea3555d 71 }
DAVIID222 0:24034ea3555d 72 }
DAVIID222 0:24034ea3555d 73 }