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.
Dependencies: mbed mbed-rtos hcsr04 TextLCD MMA8451Q
Revision 0:a07af2ea22c3, committed 2020-06-11
- Comitter:
- Diego_Mbed
- Date:
- Thu Jun 11 02:07:45 2020 +0000
- Commit message:
- Rtos;
Changed in this revision
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/MMA8451Q.lib Thu Jun 11 02:07:45 2020 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/emilmont/code/MMA8451Q/#c4d879a39775
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/TextLCD.lib Thu Jun 11 02:07:45 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/teams/KRAI-ITB-2019/code/TextLCD/#95892122f5d0
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/hcsr04.lib Thu Jun 11 02:07:45 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/lavioros/code/hcsr04/#4947ffc8c310
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Thu Jun 11 02:07:45 2020 +0000
@@ -0,0 +1,122 @@
+#include "mbed.h"
+#include "rtos.h"
+#include "hcsr04.h"
+#include "TextLCD.h"
+//#include "platform/mbed_thread.h"
+#include "MMA8451Q.h"
+#define MMA8451_I2C_ADDRESS (0x1d<<1)
+
+BusOut Dis7seg(PTE20,PTB2,PTB0,PTE21,PTE23,PTB3,PTB1);
+DigitalOut unidad(PTE2);
+DigitalOut decena(PTE3);
+DigitalOut centena(PTE5);
+Serial pc(USBTX, USBRX); // tx, rx
+HCSR04 usensor(PTD0,PTD5); // Trigger, Echo
+PwmOut servo(PTA13);
+DigitalOut led_1(LED1);
+SPI spi(PTD2, NC, PTD1); // puertos (MOSI, MISO, SCLK)
+DigitalOut cs(PTE31); // Chip select
+MMA8451Q acc(PTE25, PTE24, MMA8451_I2C_ADDRESS); //(SDA,SCL,Direc)
+// I2C Communication
+I2C i2c_lcd(PTE0,PTE1); // SDA, SCL
+// LCD instantiation
+TextLCD_I2C lcd(&i2c_lcd, 0x4E, TextLCD::LCD16x2, TextLCD::WS0010);
+
+unsigned int dist;
+int distancias[12];
+int incremento;
+int Decremento;
+int uni =5;
+int dec =2;
+int n=0;
+int p=0;
+
+//------------------------------------Funcion de números--------------------------------------------------------
+
+void numeros(){
+ switch(n){
+ case 0: Dis7seg=0x01; break;
+ case 1: Dis7seg=0x4F; break;
+ case 2: Dis7seg=0x12; break;
+ case 3: Dis7seg=0x06; break;
+ case 4: Dis7seg=0x4C; break;
+ case 5: Dis7seg=0x24; break;
+ case 6: Dis7seg=0x60; break;
+ case 7: Dis7seg=0x0F; break;
+ case 8: Dis7seg=0x00; break;
+ case 9: Dis7seg=0x0C; break;
+ }
+}
+//---------------------------------Sensor ultrasonico con servo-------------------------------------------------------------------
+void lidar(){
+ servo.period_ms(20);
+ while(true){
+ for(int i=0;i<=12;i++){
+ incremento= i*159;
+ usensor.start();
+ dist=usensor.get_dist_cm();
+ distancias[i]=dist;
+ servo.pulsewidth_us(600+incremento);
+ ThisThread::sleep_for(120);
+ }
+ for(int i=0;i<=12;i++){
+ Decremento= i*159;
+ usensor.start();
+ usensor.get_dist_cm();
+ distancias[i]=dist;
+ servo.pulsewidth_us(2508-Decremento);
+ ThisThread::sleep_for(120);
+ }
+ }
+}
+
+//---------------------------------------Lcd_I2C---------------------------------------------------------
+
+void Lcd_I2C(){
+
+ lcd.cls();
+ lcd.locate(0,0);
+ lcd.setBacklight(TextLCD::LightOn);
+
+ while(true) {
+ lcd.cls();
+ lcd.locate(0,0);
+ lcd.printf("cm:%u hola mundo",dist);
+ ThisThread::sleep_for(100);
+ }
+}
+
+//--------------------------------Visualizacion Display 7 segmentos---------------------------------------------
+
+void Seg(){
+while (true) {
+ unidad=0b1;
+ decena=0b0;
+ n=uni;
+ numeros();
+ thread_sleep_for(5);
+ unidad=0b0;
+ decena=0b1;
+ n=dec;
+ numeros();
+ thread_sleep_for(5);
+ }
+}
+
+//--------------------------Hilos tareas-------------------------------------------------------------------
+
+Thread Thread_lidar (osPriorityNormal1,OS_STACK_SIZE,nullptr, "tarea lidar");
+Thread Thread_Lcd (osPriorityNormal,OS_STACK_SIZE,nullptr, "tarea Lcd");
+Thread Thread_Dis7seg (osPriorityNormal,OS_STACK_SIZE,nullptr, "tarea 7seg");
+
+
+
+int main(){
+
+ //Thread_lidar.start(lidar);
+ Thread_Lcd.start(Lcd_I2C);
+ Thread_Dis7seg.start(Seg);
+
+
+}
+
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed-rtos.lib Thu Jun 11 02:07:45 2020 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed-rtos/#5713cbbdb706
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Thu Jun 11 02:07:45 2020 +0000 @@ -0,0 +1,1 @@ +https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400 \ No newline at end of file