Bruno St-Georges
/
Question6
q6
Question6.cpp@0:a0cba8c797e8, 2019-10-22 (annotated)
- Committer:
- brunostgr
- Date:
- Tue Oct 22 13:40:12 2019 +0000
- Revision:
- 0:a0cba8c797e8
q6
Who changed what in which revision?
User | Revision | Line number | New contents of line |
---|---|---|---|
brunostgr | 0:a0cba8c797e8 | 1 | #include "mbed.h" |
brunostgr | 0:a0cba8c797e8 | 2 | |
brunostgr | 0:a0cba8c797e8 | 3 | AnalogIn analog_value(PA_0); |
brunostgr | 0:a0cba8c797e8 | 4 | |
brunostgr | 0:a0cba8c797e8 | 5 | I2C i2c(I2C_SDA,I2C_SCL); |
brunostgr | 0:a0cba8c797e8 | 6 | Serial PC(USBTX, USBRX); |
brunostgr | 0:a0cba8c797e8 | 7 | |
brunostgr | 0:a0cba8c797e8 | 8 | // Programme principal |
brunostgr | 0:a0cba8c797e8 | 9 | int main() |
brunostgr | 0:a0cba8c797e8 | 10 | { |
brunostgr | 0:a0cba8c797e8 | 11 | // Declaration des variables |
brunostgr | 0:a0cba8c797e8 | 12 | float mesure; |
brunostgr | 0:a0cba8c797e8 | 13 | float temp; |
brunostgr | 0:a0cba8c797e8 | 14 | char nb[1]; // Tableau de donnees |
brunostgr | 0:a0cba8c797e8 | 15 | const int POT = 0xA9; // Adresse du potentiometre |
brunostgr | 0:a0cba8c797e8 | 16 | |
brunostgr | 0:a0cba8c797e8 | 17 | while(1) { |
brunostgr | 0:a0cba8c797e8 | 18 | |
brunostgr | 0:a0cba8c797e8 | 19 | // Conversion |
brunostgr | 0:a0cba8c797e8 | 20 | mesure = analog_value.read(); // Assigne une valeur de 0.0 à 1.0 a mesure |
brunostgr | 0:a0cba8c797e8 | 21 | temp = mesure * 330; // Conversion en degres Celsius |
brunostgr | 0:a0cba8c797e8 | 22 | |
brunostgr | 0:a0cba8c797e8 | 23 | // Affichage de la temperature |
brunostgr | 0:a0cba8c797e8 | 24 | PC.printf("Temperature = %u C",(unsigned)temp); |
brunostgr | 0:a0cba8c797e8 | 25 | |
brunostgr | 0:a0cba8c797e8 | 26 | // Envoi au pot |
brunostgr | 0:a0cba8c797e8 | 27 | nb[0] = 256 * mesure; |
brunostgr | 0:a0cba8c797e8 | 28 | i2c.write(POT,nb,1,0); |
brunostgr | 0:a0cba8c797e8 | 29 | } |
brunostgr | 0:a0cba8c797e8 | 30 | } |