utilisation des entrees analogiques + entree digitale

Dependencies:   BSP_B-L475E-IOT01 mbed

Fork of DISCO_L475VG_IOT01-QSPI-BSP by ST

Committer:
msouchet
Date:
Mon Jan 22 09:08:33 2018 +0000
Revision:
4:48fd4b00cfce
Parent:
1:91efecd390b4
Child:
5:91752c00a470
projet TS-SI

Who changed what in which revision?

UserRevisionLine numberNew contents of line
bcostm 0:e625f731ec74 1 #include "mbed.h"
bcostm 0:e625f731ec74 2
bcostm 0:e625f731ec74 3 DigitalOut led1(LED1);
msouchet 4:48fd4b00cfce 4 AnalogIn Temperature_entree(A0);
msouchet 4:48fd4b00cfce 5 AnalogIn Temperature_sortie(A1);
msouchet 4:48fd4b00cfce 6 InterruptIn Compteur_elec(D7);
msouchet 4:48fd4b00cfce 7 Timer Chronometre;
bcostm 0:e625f731ec74 8
msouchet 4:48fd4b00cfce 9 unsigned short sensor_value;
msouchet 4:48fd4b00cfce 10 bool temps_valide = false;
msouchet 4:48fd4b00cfce 11 bool Chronometre_alume = false;
msouchet 4:48fd4b00cfce 12 float temps_mesure = 0.0;
msouchet 4:48fd4b00cfce 13 float temps_debut = 0.0;
msouchet 4:48fd4b00cfce 14 float temps_fin = 0.0;
msouchet 4:48fd4b00cfce 15
msouchet 4:48fd4b00cfce 16
msouchet 4:48fd4b00cfce 17 void Mesure_nrj() {
msouchet 4:48fd4b00cfce 18 if (Chronometre_alume) {
msouchet 4:48fd4b00cfce 19 temps_mesure = Chronometre.read();
msouchet 4:48fd4b00cfce 20 Chronometre.reset();
msouchet 4:48fd4b00cfce 21 temps_valide = true;
msouchet 4:48fd4b00cfce 22 } else {
msouchet 4:48fd4b00cfce 23 Chronometre.reset();
msouchet 4:48fd4b00cfce 24 Chronometre_alume = true;
msouchet 4:48fd4b00cfce 25 temps_valide = false;
msouchet 4:48fd4b00cfce 26 }
msouchet 4:48fd4b00cfce 27 }
msouchet 4:48fd4b00cfce 28
bcostm 0:e625f731ec74 29
bcostm 0:e625f731ec74 30 int main()
bcostm 0:e625f731ec74 31 {
msouchet 4:48fd4b00cfce 32 Chronometre.start();
msouchet 4:48fd4b00cfce 33 Compteur_elec.rise(&Mesure_nrj);
bcostm 0:e625f731ec74 34 while(1) {
bcostm 1:91efecd390b4 35 led1 = !led1;
msouchet 4:48fd4b00cfce 36 sensor_value = Temperature_entree.read_u16();
msouchet 4:48fd4b00cfce 37 printf("\nTEMPERATURE A0 = %d \n", sensor_value);
msouchet 4:48fd4b00cfce 38
msouchet 4:48fd4b00cfce 39 sensor_value = Temperature_sortie.read_u16();
msouchet 4:48fd4b00cfce 40 printf("\nTEMPERATURE A1 = %d \n", sensor_value);
msouchet 4:48fd4b00cfce 41
msouchet 4:48fd4b00cfce 42 if (temps_valide) { printf("\nTemps entre deux impulsions (s) = %f \n", temps_mesure);
msouchet 4:48fd4b00cfce 43 temps_valide = false; }
bcostm 1:91efecd390b4 44 wait(1.0);
bcostm 0:e625f731ec74 45 }
bcostm 0:e625f731ec74 46 }