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@1:b4442f77d497, 2021-12-20 (annotated)
- Committer:
- agat
- Date:
- Mon Dec 20 21:37:50 2021 +0000
- Revision:
- 1:b4442f77d497
- Parent:
- 0:dd79e9efee0d
Examen de Javi
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| javiervicente | 0:dd79e9efee0d | 1 | #include "mbed.h" |
| javiervicente | 0:dd79e9efee0d | 2 | |
| javiervicente | 0:dd79e9efee0d | 3 | |
| javiervicente | 0:dd79e9efee0d | 4 | AnalogIn adc_temp(ADC_TEMP); |
| javiervicente | 0:dd79e9efee0d | 5 | |
| agat | 1:b4442f77d497 | 6 | enum estados {inicio, esperandopulso, mostrartemp, esperandopulsodos } estado; |
| javiervicente | 0:dd79e9efee0d | 7 | |
| agat | 1:b4442f77d497 | 8 | const float AVG_SLOPE = 4.3E-03; |
| agat | 1:b4442f77d497 | 9 | const float V30 = 1.43; |
| javiervicente | 0:dd79e9efee0d | 10 | |
| javiervicente | 0:dd79e9efee0d | 11 | DigitalOut led(LED1); |
| javiervicente | 0:dd79e9efee0d | 12 | DigitalIn boton(USER_BUTTON); |
| agat | 1:b4442f77d497 | 13 | float temperatura; |
| agat | 1:b4442f77d497 | 14 | float mediatemp; |
| agat | 1:b4442f77d497 | 15 | int contador; |
| agat | 1:b4442f77d497 | 16 | Timer t; |
| agat | 1:b4442f77d497 | 17 | |
| agat | 1:b4442f77d497 | 18 | void estadoinicio() { |
| agat | 1:b4442f77d497 | 19 | if (boton ==1) |
| agat | 1:b4442f77d497 | 20 | { |
| agat | 1:b4442f77d497 | 21 | estado = esperandopulso; |
| agat | 1:b4442f77d497 | 22 | } |
| agat | 1:b4442f77d497 | 23 | } |
| agat | 1:b4442f77d497 | 24 | |
| agat | 1:b4442f77d497 | 25 | void estadoesperandopulso() |
| agat | 1:b4442f77d497 | 26 | { |
| agat | 1:b4442f77d497 | 27 | if (boton==0) { |
| agat | 1:b4442f77d497 | 28 | estado = mostrartemp; |
| agat | 1:b4442f77d497 | 29 | t.reset(); |
| agat | 1:b4442f77d497 | 30 | } |
| agat | 1:b4442f77d497 | 31 | } |
| agat | 1:b4442f77d497 | 32 | |
| agat | 1:b4442f77d497 | 33 | void estadomostrartemp() |
| agat | 1:b4442f77d497 | 34 | { |
| agat | 1:b4442f77d497 | 35 | if (t.read()>4.0) { |
| agat | 1:b4442f77d497 | 36 | printf("Mostrar la temperatura media %f\n", mediatemp/contador); |
| agat | 1:b4442f77d497 | 37 | printf("Mostrar el contador %d\n", contador); |
| agat | 1:b4442f77d497 | 38 | mediatemp = 0; |
| agat | 1:b4442f77d497 | 39 | contador = 0; |
| agat | 1:b4442f77d497 | 40 | estado = inicio; |
| agat | 1:b4442f77d497 | 41 | |
| agat | 1:b4442f77d497 | 42 | } else if (boton==1) { |
| agat | 1:b4442f77d497 | 43 | temperatura= (V30-adc_temp.read()*3.3)/ AVG_SLOPE + 30; // con el plus ese se van sumando todos los valores de la temperatura calculada |
| agat | 1:b4442f77d497 | 44 | mediatemp+= temperatura; |
| agat | 1:b4442f77d497 | 45 | contador++; |
| agat | 1:b4442f77d497 | 46 | printf("La temperatura es de %f\n", temperatura); |
| agat | 1:b4442f77d497 | 47 | estado= esperandopulsodos; |
| agat | 1:b4442f77d497 | 48 | } |
| agat | 1:b4442f77d497 | 49 | } |
| agat | 1:b4442f77d497 | 50 | |
| agat | 1:b4442f77d497 | 51 | void estadoesperandopulsodos() |
| agat | 1:b4442f77d497 | 52 | { |
| agat | 1:b4442f77d497 | 53 | if (t.read ()<0.5 && boton ==0) { |
| agat | 1:b4442f77d497 | 54 | led = !led; |
| agat | 1:b4442f77d497 | 55 | estado = inicio; |
| agat | 1:b4442f77d497 | 56 | } else if (t.read()>0.5) { |
| agat | 1:b4442f77d497 | 57 | estado= inicio; |
| agat | 1:b4442f77d497 | 58 | } |
| agat | 1:b4442f77d497 | 59 | } |
| javiervicente | 0:dd79e9efee0d | 60 | |
| javiervicente | 0:dd79e9efee0d | 61 | int main() |
| javiervicente | 0:dd79e9efee0d | 62 | { |
| agat | 1:b4442f77d497 | 63 | estado=inicio; |
| agat | 1:b4442f77d497 | 64 | t.start(); |
| javiervicente | 0:dd79e9efee0d | 65 | while(1) { |
| agat | 1:b4442f77d497 | 66 | switch (estado) { |
| agat | 1:b4442f77d497 | 67 | case inicio: |
| agat | 1:b4442f77d497 | 68 | estadoinicio(); |
| agat | 1:b4442f77d497 | 69 | break; |
| agat | 1:b4442f77d497 | 70 | case esperandopulso: |
| agat | 1:b4442f77d497 | 71 | estadoesperandopulso(); |
| agat | 1:b4442f77d497 | 72 | break; |
| agat | 1:b4442f77d497 | 73 | case mostrartemp: |
| agat | 1:b4442f77d497 | 74 | estadomostrartemp(); |
| agat | 1:b4442f77d497 | 75 | break; |
| agat | 1:b4442f77d497 | 76 | case esperandopulsodos: |
| agat | 1:b4442f77d497 | 77 | estadoesperandopulsodos(); |
| agat | 1:b4442f77d497 | 78 | break; |
| agat | 1:b4442f77d497 | 79 | } |
| javiervicente | 0:dd79e9efee0d | 80 | } |
| javiervicente | 0:dd79e9efee0d | 81 | } |