TermometroAudio

Código Parcial


#include <SPI.h>
#include <SD.h>
#include <TMRpcm.h>

#define pinoChipSelectSD 53

TMRpcm audioCartaoSD;

const int SENSOR_LM35 = A0;
const float CONVERSAO_CELSIUS = 0.49;

int leituraSensor;
float temperaturaAtual, temperaturaAnterior;
String valorTemp;

void setup(){  
     Serial.begin(9600);
  while (!Serial) {
    ; // wait for serial port to connect. Needed for native USB port only
  }


  Serial.print("Initializing SD card...");

  if (!SD.begin(4)) {
    Serial.println("initialization failed!");
    while (1);
  }
  Serial.println("initialization done.");

    pinMode(SENSOR_LM35, INPUT);
    audioCartaoSD.speakerPin = 11;
}

void loop(){  
    temperaturaAtual = analogRead(SENSOR_LM35) * CONVERSAO_CELSIUS;
    if(temperaturaAtual != temperaturaAnterior) {
        temperaturaAnterior = temperaturaAtual;

        valorTemp = String(int(temperaturaAtual));
        valorTemp.concat(".wav");

        char nomeArquivo[valorTemp.length( ) + 1];
        valorTemp.toCharArray(nomeArquivo, sizeof(nomeArquivo));        

        audioCartaoSD.play("temp.wav");
        while(audioCartaoSD.isPlaying());
        audioCartaoSD.play(nomeArquivo);
        while(audioCartaoSD.isPlaying());
        audioCartaoSD.play("graus.wav");

        Serial.println(temperaturaAtual);
        delay(5000);        
    }
}

Page last modified on April 16, 2019, at 06:32 PM