TP

Dependencies:   mbed LCD

Committer:
theilor
Date:
Mon May 16 17:38:33 2022 +0000
Revision:
0:08b3a1ec047a
led tp

Who changed what in which revision?

UserRevisionLine numberNew contents of line
theilor 0:08b3a1ec047a 1 #include "mbed.h"
theilor 0:08b3a1ec047a 2
theilor 0:08b3a1ec047a 3 AnalogIn pot1(p19); // Potentiomètre 1
theilor 0:08b3a1ec047a 4 AnalogIn pot2(p20); // Potentiomètre 2
theilor 0:08b3a1ec047a 5
theilor 0:08b3a1ec047a 6 Timer Tcalcul,Taffichage ; // Timer
theilor 0:08b3a1ec047a 7 int a, b ; // Compteur
theilor 0:08b3a1ec047a 8
theilor 0:08b3a1ec047a 9 float ReadPot1=0, ReadPot=0, Moy1=0,Moy=0;
theilor 0:08b3a1ec047a 10
theilor 0:08b3a1ec047a 11 // Fonction lecture des potentiometres
theilor 0:08b3a1ec047a 12
theilor 0:08b3a1ec047a 13 void LecturePot()
theilor 0:08b3a1ec047a 14 {
theilor 0:08b3a1ec047a 15 ReadPot1 = ReadPot1+ pot1.read();
theilor 0:08b3a1ec047a 16 ReadPot2 = ReadPot2+ pot2.read();
theilor 0:08b3a1ec047a 17 a++;
theilor 0:08b3a1ec047a 18 b++;
theilor 0:08b3a1ec047a 19 }
theilor 0:08b3a1ec047a 20
theilor 0:08b3a1ec047a 21
theilor 0:08b3a1ec047a 22 // Fonction de calcul des potentiometres
theilor 0:08b3a1ec047a 23
theilor 0:08b3a1ec047a 24 void Moyenne()
theilor 0:08b3a1ec047a 25 {
theilor 0:08b3a1ec047a 26 Tcalcul.start();
theilor 0:08b3a1ec047a 27
theilor 0:08b3a1ec047a 28 Moy1= ReadPot1/a;
theilor 0:08b3a1ec047a 29 Moy2= ReadPot2/b;
theilor 0:08b3a1ec047a 30
theilor 0:08b3a1ec047a 31 Tcalcul.stop();
theilor 0:08b3a1ec047a 32
theilor 0:08b3a1ec047a 33 }
theilor 0:08b3a1ec047a 34
theilor 0:08b3a1ec047a 35
theilor 0:08b3a1ec047a 36
theilor 0:08b3a1ec047a 37 // Fonction d'affichage des moyennes
theilor 0:08b3a1ec047a 38 void Affichage()
theilor 0:08b3a1ec047a 39 {
theilor 0:08b3a1ec047a 40 Taffichage.start();
theilor 0:08b3a1ec047a 41 lcd.cls();
theilor 0:08b3a1ec047a 42 lcd.printf("MoyennePot1: %f MoyennePot2: %f ",Moy1,Moy2);
theilor 0:08b3a1ec047a 43 lcd.printf("Temps de calcul : %f Temps d'affichage: %f",Tcalcul,Taffichage);
theilor 0:08b3a1ec047a 44
theilor 0:08b3a1ec047a 45 Taffichage.stop();
theilor 0:08b3a1ec047a 46
theilor 0:08b3a1ec047a 47 }
theilor 0:08b3a1ec047a 48
theilor 0:08b3a1ec047a 49
theilor 0:08b3a1ec047a 50
theilor 0:08b3a1ec047a 51
theilor 0:08b3a1ec047a 52 int main()
theilor 0:08b3a1ec047a 53 {
theilor 0:08b3a1ec047a 54 while(1)
theilor 0:08b3a1ec047a 55 {
theilor 0:08b3a1ec047a 56 LecturePot();
theilor 0:08b3a1ec047a 57 Moyenne();
theilor 0:08b3a1ec047a 58 Affichage();
theilor 0:08b3a1ec047a 59 }
theilor 0:08b3a1ec047a 60
theilor 0:08b3a1ec047a 61
theilor 0:08b3a1ec047a 62
theilor 0:08b3a1ec047a 63
theilor 0:08b3a1ec047a 64 }