final digitales

Dependencies:   mbed Servo

Files at this revision

API Documentation at this revision

Comitter:
mstorress
Date:
Thu Jun 03 01:06:01 2021 +0000
Commit message:
final digitales;

Changed in this revision

Servo.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.bld Show annotated file Show diff for this revision Revisions of this file
diff -r 000000000000 -r f399a42da55e Servo.lib
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Servo.lib	Thu Jun 03 01:06:01 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/simon/code/Servo/#36b69a7ced07
diff -r 000000000000 -r f399a42da55e main.cpp
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Thu Jun 03 01:06:01 2021 +0000
@@ -0,0 +1,124 @@
+#include "mbed.h"
+#include "Servo.h"
+
+PwmOut fan(PB_10); //ventilador
+DigitalOut heater(PB_5); //calentador
+InterruptIn inicio(USER_BUTTON); //boton led tarjeta
+DigitalOut led(LED1); //led tarjeta
+
+Servo gate_1(PB_3);
+Servo gate_2(PA_10);
+
+I2C tempsensor(PB_4,PA_8);   /// Recursos para el uso de I2C
+InterruptIn alarma(PB_10);//alarma
+Serial pc(USBTX, USBRX); //tx, rx
+
+//recursos para uso de SPI
+SPI spi(PA_7, PA_6, PA_5); // mosi, miso, sclk
+DigitalOut cs(PB_6);
+
+const int addr = 0x90;  //Dirección I2C
+char config_t[3]; // Arreglo que apunta al pointer register y los registros de configuración
+char temp_read[2]; // Arreglo para la lectura de temperatura
+float temp; //Variable que almacena la conversión numérica de los valores
+
+void alerta(void);
+void calentar(void);
+void temp80(void);
+void temp60(void);
+void temp30(void);
+void temp25(void);
+
+
+
+int main()
+
+{
+    alarma.rise(&temp80);
+    inicio.fall(&calentar);
+    cs = 1;
+
+    gate_1=1;
+    gate_2=0;
+
+    config_t[0] = 0x01; // Pointer register ----> Registro de configuración
+    config_t[1] = 0x62; // Registro de configuración 1
+    config_t[2] = 0xA0; // Registro de configuración 2
+    tempsensor.write(addr, config_t, 3); // Etapa de escritura
+
+    config_t[0] = 0x03; // HIGH TEM
+    config_t[1] = 0x32; // Registro de configuración 1
+    config_t[2] = 0x00; // Registro de configuración 2
+    tempsensor.write(addr, config_t, 3); // Etapa de escritura
+
+    config_t[0] = 0x00; // Pointer register ----> registro de lectura
+    tempsensor.write(addr, config_t, 1);
+
+    fan.period(4.0f);
+
+    pc.printf("welcome \n\r en espera para iniciar \n\r");
+
+    while(1) {
+
+        tempsensor.read(addr, temp_read, 2);
+        temp = 0.0625 * (((temp_read[0] << 8) + temp_read[1]) >> 4);
+        pc.printf("Temp = %.2f degC\n\r", temp);
+
+        //ENVIO DE DATOS PARA GRAFICAR
+        cs = 0;
+        spi.format(8,3);
+        spi.frequency(1000000);
+
+        spi.write(0x8F);
+
+        int whoami = spi.write(0x00);
+        printf("WHOAMI register = 0x%X\n", whoami);
+        cs = 1;
+
+    }
+}
+
+void temp80 (void)
+{
+    pc.printf("80 Grados ALERTA!!!\n\r");
+    heater=0;
+    fan.write(1.0f);
+    gate_1=0;
+    gate_2=0;
+    while (temp>=60) {}
+    void tem60(void);
+
+}
+
+void tem60(void)
+{
+    heater=0;
+    fan.write(0.5f);
+    while (temp>=30) {}
+    void tem30(void);
+
+}
+void temp30(void)
+{
+    heater=0;
+    fan.write(0.25f);
+    while (temp>=25) {}
+    void tem25(void);
+
+}
+void temp25(void)
+{
+    fan.write(0.0f);
+    gate_1=1;
+    gate_2=1;
+    wait(0.5);
+    heater=1;
+}
+
+void calentar(void)
+{
+    wait(5);
+    gate_2=1;
+    wait(0.5);
+    heater=1;
+}
diff -r 000000000000 -r f399a42da55e mbed.bld
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Thu Jun 03 01:06:01 2021 +0000
@@ -0,0 +1,1 @@
+https://os.mbed.com/users/mbed_official/code/mbed/builds/65be27845400
\ No newline at end of file