Proyecto escolar
Dependencies: mbed FXOS8700Q TextLCD
main.cpp
- Committer:
- thesad
- Date:
- 2020-06-04
- Revision:
- 0:c64c42c6b39b
File content as of revision 0:c64c42c6b39b:
#include "mbed.h" #include "C12832.h" #include "Sht31.h" C12832 lcd(SPI_MOSI, SPI_SCK, SPI_MISO, p8, p11); PwmOut speaker(p21); AnalogIn pot(p15); DigitalOut L1(p5); DigitalIn bt(p20); Sht31 sht31(I2C_SDA, I2C_SCL); void play_tone(float frequency, float volume, float interval, float rest) { speaker.period(1.0 / frequency); speaker = volume; wait(interval); speaker = 0.0; wait(rest); } int main() { printf("Práctica 7, equipo 3\n"); int i, s; float x; x = pot.read(); s = 5; lcd.cls(); for(int x = 0; x < 0.4; ){ lcd.locate(1,1); lcd.printf("Precalentando"); lcd.copy_to_lcd(); wait(0.5); lcd.cls(); wait(1); lcd.locate(1,1); lcd.printf("Precalentando"); lcd.copy_to_lcd(); wait(0.5); lcd.cls(); wait(1); lcd.locate(1,1); lcd.printf("Precalentando"); lcd.copy_to_lcd(); wait(0.5); lcd.cls(); wait(1); lcd.locate(1,1); lcd.printf("Precalentando"); lcd.copy_to_lcd(); wait(0.5); lcd.cls(); wait(1); lcd.cls(); lcd.locate(1,1); lcd.printf("Precalentando"); lcd.copy_to_lcd(); } while(1){ if(bt == 1){ x = pot.read(); lcd.cls(); for(x = .25; x < .35 ; ){ lcd.cls(); lcd.printf("Niveles de C02 normales"); lcd.copy_to_lcd(); play_tone(450.0, 0.5, 1, 1.5);} for(x = .350; x < 1; ){ lcd.cls(); lcd.printf("Congestionado, pero con buen intercambio de aire."); lcd.copy_to_lcd(); play_tone(460.0, 0.5, 1, 1);} for(x = 1; x < 2; ){ lcd.cls(); lcd.printf("Calidad de aire baja"); lcd.copy_to_lcd(); play_tone(470.0, 0.5, 1, 0.7);} for(x = 2; x < 5; ){ lcd.cls(); lcd.printf("Peligro"); lcd.copy_to_lcd(); play_tone(480.0, 0.5, 0.7, 0.5);} if(x == 5){ L1 = 1; lcd.cls(); lcd.printf("¡Aléjate!"); lcd.copy_to_lcd(); play_tone(500.0, 0.5, 0.5, 0.1);} if(x == 0){ lcd.cls(); lcd.printf("Error"); lcd.copy_to_lcd();} } else{ printf("Si el led enciende, significa peligro"); lcd.cls(); float temp = sht31.readTemperature(); float humidity = sht31.readHumidity(); lcd.locate(3, 3); lcd.printf("Temperature: %.2f C", temp); lcd.locate(3, 13); lcd.printf("Humidity: %.2f %%", humidity); L1 = temp > 40.0f; wait(0.5f); } } }