Radar detector de obstáculos con sensor ultrasonido y motor paso a paso

Dependencies:   mbed mbed-STM32F103C8T6 USBDevice_STM32F103 TextLCD HCSR04

Files at this revision

API Documentation at this revision

Comitter:
michjpr
Date:
Thu Nov 18 03:25:19 2021 +0000
Commit message:
Redar deteccion de obstaculos con ultrasonido y motor paso a paso

Changed in this revision

HCSR042.lib Show annotated file Show diff for this revision Revisions of this file
TextLCD.lib Show annotated file Show diff for this revision Revisions of this file
USBDevice_STM32F103.lib Show annotated file Show diff for this revision Revisions of this file
main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed-STM32F103C8T6.lib Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r 29c68dc30a1e HCSR042.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/HCSR042.lib	Thu Nov 18 03:25:19 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/prabhuvd/code/HCSR04/#71da0dbf4400
diff -r 000000000000 -r 29c68dc30a1e TextLCD.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/TextLCD.lib	Thu Nov 18 03:25:19 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/oscarvzfz/code/TextLCD/#d824a83e56e3
diff -r 000000000000 -r 29c68dc30a1e USBDevice_STM32F103.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/USBDevice_STM32F103.lib	Thu Nov 18 03:25:19 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/hudakz/code/USBDevice_STM32F103/#a6dcac43ceaf
diff -r 000000000000 -r 29c68dc30a1e main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Nov 18 03:25:19 2021 +0000
@@ -0,0 +1,122 @@
+#include "stm32f103c8t6.h"
+#include "USBSerial.h"
+#include "mbed.h"
+//#include "HCSR04.h"
+#include "hcsr04.h"
+#include "TextLCD.h" 
+Serial pc(USBTX,USBRX);
+HCSR04 ultra(PA_0,PA_1);
+//BusOut motor(PA_4,PA_5,PA_6,PA_7);
+DigitalOut a(PA_4);
+DigitalOut a_(PA_5);
+DigitalOut b(PA_6);
+DigitalOut b_(PA_7);
+int Velocidad = 10000;
+I2C i2c_lcd(PB_9,PB_8); // SDA, SCL
+TextLCD_I2C lcd(&i2c_lcd,0x4E, TextLCD::LCD16x2, TextLCD::HD44780);
+unsigned int dist;
+float range=0;
+int centimetros=0;
+int distancias[2][24];
+int menord=10000;
+int menora=180;
+int tiempo=10000;
+BusOut Anodos(PA_8, PA_9, PA_10, PA_11, PA_12, PA_15, PB_3);
+BusOut Catodos(PB_4,PB_5);
+Ticker ticker1;
+int numeroSeg[10]={0b0111111, 0b0000110, 0b1011011, 0b1001111, 0b1100110, 0b1101101, 0b1111101, 0b0000111, 0b1111111, 0b1101111};
+int numeroCat[2]={0b01, 0b10};
+int menorvec[2];
+int contadorsegmentos=0;
+int i=0;
+   void rotate(){
+     if(i>3){
+        i=0; }
+    else if(i<0){
+         i=3; }
+    if(i==0){
+        a=1;
+        a_=0;
+        b=0;
+        b_=1; }
+    else if(i==1){
+        a=1;
+        a_=0;
+        b=1;
+        b_=0; }
+    else if(i==2){
+        a=0;
+        a_=1;
+        b=1;
+        b_=0; }
+    else if(i==3){
+        a=0;
+        a_=1;
+        b=0;
+        b_=1; }      
+   wait(0.01);
+}
+void cw(uint16_t step){
+  for(int count=0;count<step;count++){
+        i++;
+        rotate();
+    }
+}
+
+void Radar(){
+lcd.setBacklight(TextLCD::LightOff);//LightOff, LightOn
+lcd.setCursor(TextLCD::CurOff_BlkOff);//CurOff_BlkOff, CurOn_BlkOff, CurOff_BlkOn, CurOn_BlkOn  
+  confSysClock(); 
+  USBSerial usbSerial(0x1f00, 0x2012, 0x0001,  false);
+    for(int i=0;i<24;i++){
+        ultra.start();
+        wait_ms(500); 
+        dist=ultra.get_dist_cm();
+        cw(170);//170
+        lcd.cls ();
+        lcd.locate(0,0);
+        lcd.printf("Fuck you men");
+        lcd.locate(0,1);
+        lcd.printf("Gonorrea");
+            distancias[1][i]=i*(360/24);
+            distancias[0][i]=dist;    
+        }        
+        for(int i=0;i<24;i++){
+        if(distancias[0][i]<menord){
+            menord=distancias[0][i];
+            menora=distancias[1][i];
+            } 
+            usbSerial.printf(" [%icm ,", distancias[0][i]);
+            usbSerial.printf(" %i]", distancias[1][i]);
+           }
+        usbSerial.printf(" menor distancia %icm,\r\n", menord);
+        usbSerial.printf(" angulo  %i.\r\n", menora);   
+        lcd.cls ();
+        lcd.locate(0,0);
+        lcd.printf("menor distancia cm:%ld",menord );
+        wait(5);
+        menorvec[0]=menord/100;
+        menorvec[1]=(menord%100)/10;
+       // menorvec[2]=menord%10;
+        }
+        void segmentos(){
+            
+           Catodos=numeroCat[contadorsegmentos];
+           Anodos=numeroSeg[menorvec[contadorsegmentos]];
+           contadorsegmentos+=1;
+           if (contadorsegmentos>2){
+               contadorsegmentos=0;
+               }
+           }
+int main()
+{
+    ticker1.attach(&segmentos, 0.002);
+    Catodos=0b00;
+
+    confSysClock(); 
+ USBSerial usbSerial(0x1f00, 0x2012, 0x0001,  false); 
+ 
+    while(1) {
+        Radar();  
+    }
+}
\ No newline at end of file
diff -r 000000000000 -r 29c68dc30a1e mbed-STM32F103C8T6.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed-STM32F103C8T6.lib	Thu Nov 18 03:25:19 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/hudakz/code/mbed-STM32F103C8T6/#727468adfd1d
diff -r 000000000000 -r 29c68dc30a1e mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Nov 18 03:25:19 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file