Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Revision 1:5b8b3a6e9f8c, committed 2020-11-18
- Comitter:
- intersect20
- Date:
- Wed Nov 18 17:00:44 2020 +0000
- Parent:
- 0:24034ea3555d
- Commit message:
- proyecto Radar;
Changed in this revision
| main.cpp | Show annotated file Show diff for this revision Revisions of this file |
diff -r 24034ea3555d -r 5b8b3a6e9f8c main.cpp
--- a/main.cpp Tue Nov 17 13:30:38 2020 +0000
+++ b/main.cpp Wed Nov 18 17:00:44 2020 +0000
@@ -2,6 +2,8 @@
#include "rtos.h"
#include "Servo.h"
+Serial pc(USBTX, USBRX);
+
DigitalOut trig(D3);
DigitalIn echo(D2);
Servo myservo(D4);
@@ -10,22 +12,24 @@
Thread hilo_tarea2;
Timer senal;
float distancia;
-
+float angle;
void tarea1(void);
void tarea2(void);
int main()
{
+
hilo_tarea1.start(tarea1);
hilo_tarea2.start(tarea2);
hilo_tarea1.set_priority(osPriorityNormal);
while (true) {
-
+
}
}
-void tarea1(void){
- while(true){
+void tarea1(void)
+{
+ while(true) {
senal.reset();
trig = 0;
wait_us(2);
@@ -37,21 +41,33 @@
while(echo==1);
senal.stop();
distancia = (senal.read_us())/58;
- printf("%.f\n\r",distancia);
+ pc.printf("%.f;%.f\n\r",angle,distancia);
ThisThread::sleep_for(50);
}
}
-void tarea2(void){
- myservo.calibrate(0.0009, 180.0);
- while(true){
- for(int i=0; i<100; i++){
- myservo = i/100.0;
- ThisThread::sleep_for(100);
- }
- for(int i=100; i>0; i--){
- myservo = i/100.0;
- ThisThread::sleep_for(100);
+void tarea2(void)
+{
+ float range = 0.0009;
+ bool direction = true;
+ float position = 0.0;
+ myservo.calibrate(range, 45.0);
+ while(true) {
+ if(direction) {
+ for (int i=-90; i< 90; i++) {
+ angle= i+90;
+ myservo.position(i);
+ wait_ms(17);
+ }
+ direction=false;
+ } else {
+ for (int i=90; i> -90; i--) {
+ angle = i+90;
+ myservo.position(i);
+ wait_ms(17);
+ }
+ direction=true;
+
}
}
}
\ No newline at end of file