Proyecto escolar
Dependencies: mbed FXOS8700Q TextLCD
main.cpp
00001 #include "mbed.h" 00002 #include "C12832.h" 00003 #include "Sht31.h" 00004 00005 C12832 lcd(SPI_MOSI, SPI_SCK, SPI_MISO, p8, p11); 00006 00007 PwmOut speaker(p21); 00008 AnalogIn pot(p15); 00009 DigitalOut L1(p5); 00010 DigitalIn bt(p20); 00011 Sht31 sht31(I2C_SDA, I2C_SCL); 00012 00013 void play_tone(float frequency, float volume, float interval, float rest) { 00014 speaker.period(1.0 / frequency); 00015 speaker = volume; 00016 wait(interval); 00017 speaker = 0.0; 00018 wait(rest); 00019 } 00020 00021 int main() { 00022 printf("Práctica 7, equipo 3\n"); 00023 00024 int i, s; 00025 float x; 00026 x = pot.read(); 00027 s = 5; 00028 00029 lcd.cls(); 00030 for(int x = 0; x < 0.4; ){ 00031 00032 lcd.locate(1,1); 00033 lcd.printf("Precalentando"); 00034 lcd.copy_to_lcd(); 00035 wait(0.5); 00036 lcd.cls(); 00037 00038 wait(1); 00039 lcd.locate(1,1); 00040 lcd.printf("Precalentando"); 00041 lcd.copy_to_lcd(); 00042 wait(0.5); 00043 lcd.cls(); 00044 00045 wait(1); 00046 lcd.locate(1,1); 00047 lcd.printf("Precalentando"); 00048 lcd.copy_to_lcd(); 00049 wait(0.5); 00050 lcd.cls(); 00051 00052 wait(1); 00053 lcd.locate(1,1); 00054 lcd.printf("Precalentando"); 00055 lcd.copy_to_lcd(); 00056 wait(0.5); 00057 lcd.cls(); 00058 00059 wait(1); 00060 lcd.cls(); 00061 lcd.locate(1,1); 00062 lcd.printf("Precalentando"); 00063 lcd.copy_to_lcd(); 00064 } 00065 00066 00067 while(1){ 00068 00069 if(bt == 1){ 00070 00071 x = pot.read(); 00072 lcd.cls(); 00073 00074 for(x = .25; x < .35 ; ){ 00075 lcd.cls(); 00076 lcd.printf("Niveles de C02 normales"); 00077 lcd.copy_to_lcd(); 00078 play_tone(450.0, 0.5, 1, 1.5);} 00079 for(x = .350; x < 1; ){ 00080 lcd.cls(); 00081 lcd.printf("Congestionado, pero con buen intercambio de aire."); 00082 lcd.copy_to_lcd(); 00083 play_tone(460.0, 0.5, 1, 1);} 00084 00085 for(x = 1; x < 2; ){ 00086 lcd.cls(); 00087 lcd.printf("Calidad de aire baja"); 00088 lcd.copy_to_lcd(); 00089 play_tone(470.0, 0.5, 1, 0.7);} 00090 00091 for(x = 2; x < 5; ){ 00092 lcd.cls(); 00093 lcd.printf("Peligro"); 00094 lcd.copy_to_lcd(); 00095 play_tone(480.0, 0.5, 0.7, 0.5);} 00096 00097 if(x == 5){ 00098 L1 = 1; 00099 lcd.cls(); 00100 lcd.printf("¡Aléjate!"); 00101 lcd.copy_to_lcd(); 00102 play_tone(500.0, 0.5, 0.5, 0.1);} 00103 00104 if(x == 0){ 00105 lcd.cls(); 00106 lcd.printf("Error"); 00107 lcd.copy_to_lcd();} 00108 00109 } 00110 else{ 00111 printf("Si el led enciende, significa peligro"); 00112 lcd.cls(); 00113 00114 float temp = sht31.readTemperature(); 00115 float humidity = sht31.readHumidity(); 00116 00117 lcd.locate(3, 3); 00118 lcd.printf("Temperature: %.2f C", temp); 00119 lcd.locate(3, 13); 00120 lcd.printf("Humidity: %.2f %%", humidity); 00121 00122 L1 = temp > 40.0f; 00123 00124 wait(0.5f); 00125 } 00126 00127 } 00128 }
Generated on Fri Sep 16 2022 21:07:57 by
1.7.2