Advertisement
caiovischi

forno

Jan 6th, 2017
256
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C 2.50 KB | None | 0 0
  1. // Sample Arduino MAX6675 Arduino Sketch
  2.  
  3. #include "max6675.h"
  4. #include <Wire.h>
  5. #include <LiquidCrystal_I2C.h>
  6. #include <MsTimer2.h> // cronometro
  7. #define BOTAO 2
  8.  
  9. LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7,3, POSITIVE);
  10. int thermoDO = 8;
  11. int thermoCS = 9;
  12. int thermoCLK = 10;
  13.  
  14. unsigned int milissegundos =0, segundos=0, minutos=0, hora=0;
  15. boolean setaCrono = true;
  16. boolean cronoLigado = false;
  17.  
  18. void ajustaCronometro () {
  19.   milissegundos++;
  20.   if ( milissegundos == 1000) {
  21.     milissegundos = 0;
  22.     segundos++;
  23.     if (segundos == 60) {
  24.       segundos = 0;
  25.       minutos ++;
  26.       if (minutos == 60){
  27.         minutos = 0;
  28.         hora ++;
  29.       }
  30.       if (hora == 2){
  31.         hora = 0;
  32.         minutos = 0;
  33.         segundos = 0;
  34.         milissegundos = 0;
  35.       }
  36.     }
  37.   }
  38.   setaCrono = true;
  39.  
  40.  
  41.  
  42. }
  43.  
  44. //Cria o objeto do Termopar e seta os Pinos Digitais
  45. MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
  46.  
  47. //Numero de amostras
  48. int amostragem = 10;
  49.  
  50. void setup() {
  51.   Serial.begin(9600);
  52.   // give the MAX a little time to settle
  53.   delay(500);
  54.   lcd.begin (16,2);
  55.   delay(200);
  56.  
  57.   Serial.begin(9600);
  58.   pinMode (BOTAO, INPUT);
  59.   digitalWrite(BOTAO,1);
  60.   MsTimer2::set (10, ajustaCronometro);
  61.  
  62.  
  63. }
  64.  
  65. void loop() {
  66.   // basic readout test
  67.    float temperatura = 0;
  68.  
  69.  //Inicia a leituira das amostra
  70.    for(int index =0; index < amostragem; index++){
  71.      temperatura = thermocouple.readCelsius() + temperatura;
  72.      delay(200);
  73.    }
  74.     //Tira a media das leituras
  75.    temperatura = temperatura / amostragem;
  76.    
  77.    //Imprime na Serial
  78.    Serial.print("C = ");
  79.    Serial.println(temperatura);
  80.    
  81.    //Serial.print("F = ");
  82.    //Serial.println(thermocouple.readFahrenheit());
  83.    
  84.    //Imprime no LCD os dados
  85.    lcd.setCursor(0,0);
  86.    // Limpa o Display
  87.    lcd.clear();
  88.    //Escreve
  89.    lcd.print("Temp:");
  90.    lcd.setCursor(5,0);
  91.    lcd.print(" ");
  92.    lcd.print(temperatura);
  93.    lcd.print(" Celsius");
  94.        delay(10);
  95.  
  96.   if ( (digitalRead (BOTAO)== LOW) && (cronoLigado == false) )
  97.   {
  98.     cronoLigado = true;
  99.     MsTimer2::start();
  100.   }
  101.   else if ( (digitalRead (BOTAO)== HIGH) && (cronoLigado == true) )
  102.   {
  103.     cronoLigado = false;
  104.     MsTimer2::stop();
  105.   }
  106.   if (setaCrono) {
  107.     Serial.print (hora,DEC);
  108.     Serial.print (':');
  109.     Serial.print (minutos,DEC);
  110.     Serial.print (':');
  111.     Serial.print (segundos,DEC);
  112.     Serial.print (':');
  113.     Serial.println (milissegundos,DEC);
  114.     setaCrono = false;
  115.  
  116.   }
  117.  
  118.  
  119. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement