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
main.cpp
00001 #include "mbed.h" 00002 00003 00004 AnalogIn adc_temp(ADC_TEMP); 00005 00006 enum estados {inicio, esperandopulso, mostrartemp, esperandopulsodos } estado; 00007 00008 const float AVG_SLOPE = 4.3E-03; 00009 const float V30 = 1.43; 00010 00011 DigitalOut led(LED1); 00012 DigitalIn boton(USER_BUTTON); 00013 float temperatura; 00014 float mediatemp; 00015 int contador; 00016 Timer t; 00017 00018 void estadoinicio() { 00019 if (boton ==1) 00020 { 00021 estado = esperandopulso; 00022 } 00023 } 00024 00025 void estadoesperandopulso() 00026 { 00027 if (boton==0) { 00028 estado = mostrartemp; 00029 t.reset(); 00030 } 00031 } 00032 00033 void estadomostrartemp() 00034 { 00035 if (t.read()>4.0) { 00036 printf("Mostrar la temperatura media %f\n", mediatemp/contador); 00037 printf("Mostrar el contador %d\n", contador); 00038 mediatemp = 0; 00039 contador = 0; 00040 estado = inicio; 00041 00042 } else if (boton==1) { 00043 temperatura= (V30-adc_temp.read()*3.3)/ AVG_SLOPE + 30; // con el plus ese se van sumando todos los valores de la temperatura calculada 00044 mediatemp+= temperatura; 00045 contador++; 00046 printf("La temperatura es de %f\n", temperatura); 00047 estado= esperandopulsodos; 00048 } 00049 } 00050 00051 void estadoesperandopulsodos() 00052 { 00053 if (t.read ()<0.5 && boton ==0) { 00054 led = !led; 00055 estado = inicio; 00056 } else if (t.read()>0.5) { 00057 estado= inicio; 00058 } 00059 } 00060 00061 int main() 00062 { 00063 estado=inicio; 00064 t.start(); 00065 while(1) { 00066 switch (estado) { 00067 case inicio: 00068 estadoinicio(); 00069 break; 00070 case esperandopulso: 00071 estadoesperandopulso(); 00072 break; 00073 case mostrartemp: 00074 estadomostrartemp(); 00075 break; 00076 case esperandopulsodos: 00077 estadoesperandopulsodos(); 00078 break; 00079 } 00080 } 00081 }
Generated on Sat Sep 16 2023 01:23:14 by
1.7.2