Michael Steven Torres / Mbed 2 deprecated proyecto-final

Dependencies:   mbed Servo

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "Servo.h"
00003 
00004 PwmOut fan(PB_10); //ventilador
00005 DigitalOut heater(PB_5); //calentador
00006 InterruptIn inicio(USER_BUTTON); //boton led tarjeta
00007 DigitalOut led(LED1); //led tarjeta
00008 
00009 Servo gate_1(PB_3);
00010 Servo gate_2(PA_10);
00011 
00012 I2C tempsensor(PB_4,PA_8);   /// Recursos para el uso de I2C
00013 InterruptIn alarma(PB_10);//alarma
00014 Serial pc(USBTX, USBRX); //tx, rx
00015 
00016 //recursos para uso de SPI
00017 SPI spi(PA_7, PA_6, PA_5); // mosi, miso, sclk
00018 DigitalOut cs(PB_6);
00019 
00020 const int addr = 0x90;  //Dirección I2C
00021 char config_t[3]; // Arreglo que apunta al pointer register y los registros de configuración
00022 char temp_read[2]; // Arreglo para la lectura de temperatura
00023 float temp; //Variable que almacena la conversión numérica de los valores
00024 
00025 void alerta(void);
00026 void calentar(void);
00027 void temp80(void);
00028 void temp60(void);
00029 void temp30(void);
00030 void temp25(void);
00031 
00032 
00033 
00034 int main()
00035 
00036 {
00037     alarma.rise(&temp80);
00038     inicio.fall(&calentar);
00039     cs = 1;
00040 
00041     gate_1=1;
00042     gate_2=0;
00043 
00044     config_t[0] = 0x01; // Pointer register ----> Registro de configuración
00045     config_t[1] = 0x62; // Registro de configuración 1
00046     config_t[2] = 0xA0; // Registro de configuración 2
00047     tempsensor.write(addr, config_t, 3); // Etapa de escritura
00048 
00049     config_t[0] = 0x03; // HIGH TEM
00050     config_t[1] = 0x32; // Registro de configuración 1
00051     config_t[2] = 0x00; // Registro de configuración 2
00052     tempsensor.write(addr, config_t, 3); // Etapa de escritura
00053 
00054     config_t[0] = 0x00; // Pointer register ----> registro de lectura
00055     tempsensor.write(addr, config_t, 1);
00056 
00057     fan.period(4.0f);
00058 
00059     pc.printf("welcome \n\r en espera para iniciar \n\r");
00060 
00061     while(1) {
00062 
00063         tempsensor.read(addr, temp_read, 2);
00064         temp = 0.0625 * (((temp_read[0] << 8) + temp_read[1]) >> 4);
00065         pc.printf("Temp = %.2f degC\n\r", temp);
00066 
00067         //ENVIO DE DATOS PARA GRAFICAR
00068         cs = 0;
00069         spi.format(8,3);
00070         spi.frequency(1000000);
00071 
00072         spi.write(0x8F);
00073 
00074         int whoami = spi.write(0x00);
00075         printf("WHOAMI register = 0x%X\n", whoami);
00076         cs = 1;
00077 
00078     }
00079 }
00080 
00081 void temp80 (void)
00082 {
00083     pc.printf("80 Grados ALERTA!!!\n\r");
00084     heater=0;
00085     fan.write(1.0f);
00086     gate_1=0;
00087     gate_2=0;
00088     while (temp>=60) {}
00089     void tem60(void);
00090 
00091 }
00092 
00093 void tem60(void)
00094 {
00095     heater=0;
00096     fan.write(0.5f);
00097     while (temp>=30) {}
00098     void tem30(void);
00099 
00100 }
00101 void temp30(void)
00102 {
00103     heater=0;
00104     fan.write(0.25f);
00105     while (temp>=25) {}
00106     void tem25(void);
00107 
00108 }
00109 void temp25(void)
00110 {
00111     fan.write(0.0f);
00112     gate_1=1;
00113     gate_2=1;
00114     wait(0.5);
00115     heater=1;
00116 }
00117 
00118 void calentar(void)
00119 {
00120     wait(5);
00121     gate_2=1;
00122     wait(0.5);
00123     heater=1;
00124 }