-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStart code
More file actions
219 lines (169 loc) · 4.86 KB
/
Start code
File metadata and controls
219 lines (169 loc) · 4.86 KB
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
#include <SPI.h>
#include "Adafruit_MAX31855.h"
#include "HX8357_t3n.h"
#include <math.h>
#include <stdio.h>
#include <elapsedMillis.h>
#include <ButtonEvents.h>
#include <ADC.h>
#include <Encoder.h>
#include <PID_v1.h>
// Default connection is using software SPI, but comment and uncomment one of
// the two examples below to switch between software SPI and hardware SPI:
// Example creating a thermocouple instance with software SPI on any three
// digital IO pins.
#define C_BLACK 0x0000
#define C_BLUE 0x001F
#define C_RED 0xF800
#define C_GREEN 0x07E0
#define C_CYAN 0x07FF
#define C_MAGENTA 0xF81F
#define C_YELLOW 0xFFE0
#define C_WHITE 0xFFFF
#define TFT_CS 10
#define TFT_RST -1
#define TFT_DC 9
#define MAXMISO 12
#define MAXCLK 13 //max31855 nothing else.
#define MAX31855_1 14
#define MAX31855_2 15
#define MAX31855_3 16
#define MAX31855_4 17
SPISettings settingsTFT(25000000, MSBFIRST, SPI_MODE3);
SPISettings SettingsA(5000000, MSBFIRST, SPI_MODE0);
// initialize the Thermocouple
Adafruit_MAX31855 TH1(MAXCLK, MAX31855_1, MAXMISO);
//constructors for TFT without flickering
HX8357_t3n tft = HX8357_t3n(TFT_CS, TFT_DC, TFT_RST);
//flickerfree variables:
float j;
unsigned long StartTime, EndTime;
char str[30];
unsigned long endmicros; //speed check variables
unsigned long currentmicros;
//arrays for the temperature
float TC1[12];
float *pArray_From_TC;
float pArray_Screen;
//Intervals execution of the various functions
//TFT update:
unsigned long ScreenpreviousMillis = 0;
unsigned long ScreenInterval = 100;//used
//Thermocouple Function update
unsigned long TC_previousMillis = 0;
unsigned long TC_Interval = 1000;//not used
//total update repeat Thermocouple + TFT every Second
unsigned long ValuespreviousMillis = 0;
unsigned long ValuesInterval = 1000;//used
elapsedMillis firstsecond;
elapsedMillis TCmillis;
elapsedMillis TFTmillis;
elapsedMillis Delaymillis;
float TFTscreen(float *pArray_Screen) //Menu 1 //Display
{
// if (pArray_Screen == nullptr)
// {
// Serial.println("TFTSCREEN- NULL pointer Passed!");
//
//
// return 0;
// }
// get some data
j += 0.0013;
currentmicros = micros();
long value;
double voltage;
Serial.println("inside the TFT function");
tft.setTextColor(C_WHITE, C_BLACK);
tft.setCursor(0, 20);
tft.setTextSize(2);
tft.println(" This is just a test");
tft.println(" this is just a test ");
tft.setTextSize(2);
tft.setTextColor(C_WHITE, C_BLACK);
tft.setCursor(20, 200);
tft.print("TempEmag: ");
Serial.println("pArray_Screen[8]");
Serial.println(pArray_Screen[8]);
tft.print(pArray_Screen[8]);
// tft.print(j, 2);
tft.print(" "); // blank out some if new string not as long as previous..
sprintf(str, "TempEmag: %.2lf\n", pArray_Screen[8]);
tft.print(str);
return 0;
}
float *Thermocouples1()
{
//use this to test the code and the pointers, you dont need to have MAX31855. good idea for debugging
// for (int i = 0; i < 12; i++) TC1[i] += 0.25;
if (TH1.readCelsius() < 0) //if temperature is lower than 0 ////Thermocouple 1
{
TC1[8] = TH1.readCelsius();
delay(10);
TC1[4] = TH1.readInternal();
if (isnan( TC1[8]))
{
Serial.print("Something wrong with Thermocouple ");
}
else {
Serial.print("C = ");
Serial.println(TC1[8]);
}
} else //this is the 0...500°
{
TC1[4] = TH1.readInternal();
TC1[8] = TH1.readCelsius();
if (isnan( TC1[8]))
{
Serial.print("Something wrong with Thermocouple ");
}
else {
Serial.print("C = ");
Serial.println(TC1[8]);
}
Serial.print("Thermocouples1 Print cArray_TC[8] = ");
Serial.println(TC1[8]);
}
return TC1;
}
void setup()
{
Serial.begin(9600);
//SPI CS pins for the MAX31855 need to be set high!
pinMode(MAX31855_1, OUTPUT); digitalWrite(MAX31855_1, HIGH);
pinMode(TFT_CS, OUTPUT); digitalWrite(TFT_CS, HIGH);
SPI.begin();
tft.begin();
tft.setRotation(1);
tft.fillScreen(C_BLACK);
tft.fillRect(0, 30, 480, 10, C_RED);
tft.fillRect(0, 140, 480, 10, C_BLUE);
uint8_t x = tft.readcommand8(HX8357_RDMODE);
Serial.print("Display Power Mode: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(HX8357_RDMADCTL);
Serial.print("MADCTL Mode: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(HX8357_RDPIXFMT);
Serial.print("Pixel Format: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(HX8357_RDIMGFMT);
Serial.print("Image Format: 0x"); Serial.println(x, HEX);
x = tft.readcommand8(HX8357_RDSELFDIAG);
Serial.print("Self Diagnostic: 0x"); Serial.println(x, HEX);
if (!TH1.begin())
{
while(1);
Serial.println("Error");
}
}
void loop()
{
if (TCmillis>=50)
{
Thermocouples1();
TCmillis=TCmillis-50;
}
else if (TFTmillis>=255)
{
TFTscreen(Thermocouples1());
TFTmillis=TFTmillis-255;
}
}