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@2:a763f2b816ed, 2022-01-07 (annotated)
- Committer:
- Giamarchi
- Date:
- Fri Jan 07 04:56:12 2022 +0000
- Revision:
- 2:a763f2b816ed
- Parent:
- 1:95172f59262a
Avec calcul de la moyenne
Who changed what in which revision?
| User | Revision | Line number | New contents of line |
|---|---|---|---|
| Giamarchi | 2:a763f2b816ed | 1 | //============================================================================== |
| Giamarchi | 2:a763f2b816ed | 2 | // FabLab Nîmes |
| Giamarchi | 2:a763f2b816ed | 3 | // Initiation à la Programmation |
| Giamarchi | 2:a763f2b816ed | 4 | // Auteur : Frédéric Giamarchi |
| Giamarchi | 2:a763f2b816ed | 5 | |
| Giamarchi | 2:a763f2b816ed | 6 | // Date : 06 janv. 2022 |
| Giamarchi | 2:a763f2b816ed | 7 | // TP : Mesure de la température par une résistance CTN de 4,7k Ohm |
| Giamarchi | 2:a763f2b816ed | 8 | // Affichage de la température sur le PC |
| Giamarchi | 2:a763f2b816ed | 9 | //============================================================================== |
| Giamarchi | 2:a763f2b816ed | 10 | // Déclarations des ressources |
| Giamarchi | 0:531f33a2550d | 11 | #include "mbed.h" |
| Giamarchi | 0:531f33a2550d | 12 | |
| Giamarchi | 2:a763f2b816ed | 13 | //============================================================================== |
| Giamarchi | 2:a763f2b816ed | 14 | // Déclaration des broches |
| Giamarchi | 2:a763f2b816ed | 15 | DigitalOut DEL_RO(PA_11); // Ligne PA_11 sur la carte Nucléo |
| Giamarchi | 2:a763f2b816ed | 16 | Serial pc(USBTX, USBRX); // Dialogue Série port USB à 9600 Baud |
| Giamarchi | 2:a763f2b816ed | 17 | AnalogIn POT(PA_0); // Ligne PA_0 en entrée analogique |
| Giamarchi | 0:531f33a2550d | 18 | |
| Giamarchi | 2:a763f2b816ed | 19 | //============================================================================== |
| Giamarchi | 2:a763f2b816ed | 20 | // Déclaration des variables |
| Giamarchi | 2:a763f2b816ed | 21 | uint8_t variable; // variable de type entier (0 à 255) |
| Giamarchi | 2:a763f2b816ed | 22 | char c; // variable de type caractère |
| Giamarchi | 2:a763f2b816ed | 23 | float temp, temp_mes; // variable de type réel |
| Giamarchi | 2:a763f2b816ed | 24 | uint16_t mesure; |
| Giamarchi | 1:95172f59262a | 25 | |
| Giamarchi | 2:a763f2b816ed | 26 | //============================================================================== |
| Giamarchi | 2:a763f2b816ed | 27 | // Déclaration des Fonctions |
| Giamarchi | 2:a763f2b816ed | 28 | float tab[100]; |
| Giamarchi | 2:a763f2b816ed | 29 | uint8_t k; |
| Giamarchi | 2:a763f2b816ed | 30 | float somme; |
| Giamarchi | 1:95172f59262a | 31 | |
| Giamarchi | 2:a763f2b816ed | 32 | // Fonction qui calcule la moyenne de x valeurs et renvoit un résultat |
| Giamarchi | 2:a763f2b816ed | 33 | float Moyenne(float valeur, uint8_t nb) |
| Giamarchi | 0:531f33a2550d | 34 | { |
| Giamarchi | 2:a763f2b816ed | 35 | somme = somme - tab[k]+ valeur; // Calcul de la somme |
| Giamarchi | 2:a763f2b816ed | 36 | tab[k] = valeur; // Mémorise la nouvelle valeur dans le tableau |
| Giamarchi | 2:a763f2b816ed | 37 | |
| Giamarchi | 2:a763f2b816ed | 38 | k++; |
| Giamarchi | 2:a763f2b816ed | 39 | if (k == nb) // Limitation du tableau à "nb" valeurs |
| Giamarchi | 2:a763f2b816ed | 40 | k = 0; |
| Giamarchi | 2:a763f2b816ed | 41 | |
| Giamarchi | 2:a763f2b816ed | 42 | return somme / nb; // Calcule de la moyenne et renvoit le résultat |
| Giamarchi | 0:531f33a2550d | 43 | } |
| Giamarchi | 0:531f33a2550d | 44 | |
| Giamarchi | 2:a763f2b816ed | 45 | //============================================================================== |
| Giamarchi | 2:a763f2b816ed | 46 | // Début du Programme |
| Giamarchi | 2:a763f2b816ed | 47 | int main() // Fonction principale |
| Giamarchi | 2:a763f2b816ed | 48 | { |
| Giamarchi | 2:a763f2b816ed | 49 | pc.printf("\r\nFabLab TP Mesure Temperature\r\n\n"); |
| Giamarchi | 2:a763f2b816ed | 50 | k = 0; |
| Giamarchi | 1:95172f59262a | 51 | |
| Giamarchi | 2:a763f2b816ed | 52 | //============================================================================== |
| Giamarchi | 2:a763f2b816ed | 53 | // Boucle Infinie |
| Giamarchi | 0:531f33a2550d | 54 | while(1) |
| Giamarchi | 0:531f33a2550d | 55 | { |
| Giamarchi | 2:a763f2b816ed | 56 | // mesure = POT.read()*3.3f; // Mesure de la tension |
| Giamarchi | 2:a763f2b816ed | 57 | mesure = POT.read_u16()>>4; // Mesure de la valeur numérique alignée à gauche qui doit être replacer à droite |
| Giamarchi | 2:a763f2b816ed | 58 | temp = (mesure - 966)*0.023f - 2; // Linéarisation et correction |
| Giamarchi | 2:a763f2b816ed | 59 | temp_mes = temp; // Température mesurée |
| Giamarchi | 2:a763f2b816ed | 60 | temp = Moyenne (temp,50); // Calcul de la moyenne sur 50 valeurs |
| Giamarchi | 1:95172f59262a | 61 | |
| Giamarchi | 2:a763f2b816ed | 62 | wait_ms(50); |
| Giamarchi | 2:a763f2b816ed | 63 | pc.printf("Mes: %.1f Moy: %.1f\r\n",temp_mes,temp); |
| Giamarchi | 2:a763f2b816ed | 64 | |
| Giamarchi | 1:95172f59262a | 65 | } // Fin du while(1) |
| Giamarchi | 2:a763f2b816ed | 66 | //============================================================================== |
| Giamarchi | 2:a763f2b816ed | 67 | } // Fin du Programme |
| Giamarchi | 2:a763f2b816ed | 68 | //============================================================================== |