-
Notifications
You must be signed in to change notification settings - Fork 12
/
AverageMeasurement.ino
72 lines (59 loc) · 1.75 KB
/
AverageMeasurement.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
/*
Average MAX6675 Thermocouple
Reads a temperature from the MAX6675 thermocouple,
averages and displays it in the default Serial.
https://github.com/YuriiSalimov/MAX6675_Thermocouple
Created by Yurii Salimov, May, 2019.
Released into the public domain.
*/
#include <Thermocouple.h>
#include <MAX6675_Thermocouple.h>
#include <AverageThermocouple.h>
#define SCK_PIN 3
#define CS_PIN 4
#define SO_PIN 5
/**
How many readings are taken to determine a mean temperature.
The more values, the longer a calibration is performed,
but the readings will be more accurate.
*/
#define READINGS_NUMBER 10
/**
Delay time between a temperature readings
from the temperature sensor (ms).
*/
#define DELAY_TIME 10
Thermocouple* thermocouple = NULL;
// the setup function runs once when you press reset or power the board
void setup() {
Serial.begin(9600);
Thermocouple* originThermocouple = new MAX6675_Thermocouple(SCK_PIN, CS_PIN, SO_PIN);
thermocouple = new AverageThermocouple(
originThermocouple,
READINGS_NUMBER,
DELAY_TIME
);
/* OR
thermocouple = new AverageThermocouple(
new MAX6675_Thermocouple(SCK_PIN, CS_PIN, SO_PIN),
READINGS_NUMBER,
DELAY_TIME
);
*/
}
// the loop function runs over and over again forever
void loop() {
// Reads temperature
const double celsius = thermocouple->readCelsius();
const double kelvin = thermocouple->readKelvin();
const double fahrenheit = thermocouple->readFahrenheit();
// Output of information
Serial.print("Temperature: ");
Serial.print(celsius);
Serial.print(" C, ");
Serial.print(kelvin);
Serial.print(" K, ");
Serial.print(fahrenheit);
Serial.println(" F");
delay(100); // optionally, only to delay the output of information in the example.
}