Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Sample Arduino MAX6675 Arduino Sketch
- #include "max6675.h"
- #include <Wire.h>
- #include <LiquidCrystal_I2C.h>
- #include <MsTimer2.h> // cronometro
- #define BOTAO 2
- LiquidCrystal_I2C lcd(0x3F,2,1,0,4,5,6,7,3, POSITIVE);
- int thermoDO = 8;
- int thermoCS = 9;
- int thermoCLK = 10;
- unsigned int milissegundos =0, segundos=0, minutos=0, hora=0;
- boolean setaCrono = true;
- boolean cronoLigado = false;
- void ajustaCronometro () {
- milissegundos++;
- if ( milissegundos == 1000) {
- milissegundos = 0;
- segundos++;
- if (segundos == 60) {
- segundos = 0;
- minutos ++;
- if (minutos == 60){
- minutos = 0;
- hora ++;
- }
- if (hora == 2){
- hora = 0;
- minutos = 0;
- segundos = 0;
- milissegundos = 0;
- }
- }
- }
- setaCrono = true;
- }
- //Cria o objeto do Termopar e seta os Pinos Digitais
- MAX6675 thermocouple(thermoCLK, thermoCS, thermoDO);
- //Numero de amostras
- int amostragem = 10;
- void setup() {
- Serial.begin(9600);
- // give the MAX a little time to settle
- delay(500);
- lcd.begin (16,2);
- delay(200);
- Serial.begin(9600);
- pinMode (BOTAO, INPUT);
- digitalWrite(BOTAO,1);
- MsTimer2::set (10, ajustaCronometro);
- }
- void loop() {
- // basic readout test
- float temperatura = 0;
- //Inicia a leituira das amostra
- for(int index =0; index < amostragem; index++){
- temperatura = thermocouple.readCelsius() + temperatura;
- delay(200);
- }
- //Tira a media das leituras
- temperatura = temperatura / amostragem;
- //Imprime na Serial
- Serial.print("C = ");
- Serial.println(temperatura);
- //Serial.print("F = ");
- //Serial.println(thermocouple.readFahrenheit());
- //Imprime no LCD os dados
- lcd.setCursor(0,0);
- // Limpa o Display
- lcd.clear();
- //Escreve
- lcd.print("Temp:");
- lcd.setCursor(5,0);
- lcd.print(" ");
- lcd.print(temperatura);
- lcd.print(" Celsius");
- delay(10);
- if ( (digitalRead (BOTAO)== LOW) && (cronoLigado == false) )
- {
- cronoLigado = true;
- MsTimer2::start();
- }
- else if ( (digitalRead (BOTAO)== HIGH) && (cronoLigado == true) )
- {
- cronoLigado = false;
- MsTimer2::stop();
- }
- if (setaCrono) {
- Serial.print (hora,DEC);
- Serial.print (':');
- Serial.print (minutos,DEC);
- Serial.print (':');
- Serial.print (segundos,DEC);
- Serial.print (':');
- Serial.println (milissegundos,DEC);
- setaCrono = false;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement