/* Código para mostrar valor em dB */ const int Sensor1AI = 0; //Sensor Analogo Interno, Entrada A0 const int PinoDigital1 = 1; const int Sensor2AI = 2; //Sensor Analogo Externo, Entrada A1 const int PinoDigital2 = 3; //int Estado = 0; int ValorSensor1 = 0; int valorMayor1 = 0; float volt1 = 0; int dB1 = 0; int ValorSensor2 = 0; int valorMayor2 = 0; float volt2 = 0; int dB2 = 0; int cont = 0; /* Board I2C / TWI pins Uno = A4 (SDA), A5 (SCL) */ #include #include LiquidCrystal_PCF8574 lcd(0x27); // set LCD address 0x27 void setup() { Serial.begin(9600); lcd.begin(16,2); // initialize 16x2 LCD lcd.setBacklight(255); // turn on backlight lcd.home(); // go home lcd.clear(); lcd.setCursor(0, 0); lcd.print("Int:"); lcd.setCursor(10, 0); lcd.print("dB"); lcd.setCursor(0, 1); lcd.print("Ext:"); lcd.setCursor(10, 1); lcd.print("dB"); } void loop() { lcd.setCursor(6,0); Serial.print(ValorSensor1); lcd.setCursor(6,1); Serial.print(ValorSensor2); while(cont < 10000) { ValorSensor1 = analogRead(Sensor1AI); if(ValorSensor1 > valorMayor1) { valorMayor1 = ValorSensor1; } ValorSensor2 = analogRead(Sensor2AI); if(ValorSensor2 > valorMayor2) { valorMayor2 = ValorSensor2; } cont++; } cont = 0; volt1 = valorMayor1/1023.0*4.53; dB1 = 87.1*volt1 - 75,4; if(dB1 < 0) { dB1 = 0; } volt2 = valorMayor2/1023.0*4.53; dB2 = 87.1*volt2- 75,4; if(dB2 < 0) { dB2 = 0; } lcd.print(""); lcd.setCursor(6,0); lcd.print(dB1); lcd.print(""); lcd.setCursor(6,1); lcd.print(dB2); valorMayor1 = 0; valorMayor2 = 0; delay(100); }