-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCode for display only.ino
More file actions
71 lines (57 loc) · 2.02 KB
/
Code for display only.ino
File metadata and controls
71 lines (57 loc) · 2.02 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
#include <Wire.h>
#include <SparkFun_SCD4x_Arduino_Library.h>
#include <TFT_eSPI.h> // Include the graphics library
TFT_eSPI tft = TFT_eSPI(); // Create a TFT_eSPI object
#define DEVICE "SCD40"
// Custom I2C pins
#define SDA_PIN 27
#define SCL_PIN 22
SCD4x mySensor;
void setup() {
Serial.begin(115200);
Serial.println(F("SCD4x Example"));
// Initialize the SCD4x sensor
Wire.begin(SDA_PIN, SCL_PIN);
if (!mySensor.begin()) {
Serial.println(F("Sensor not detected. Please check wiring. Continuing without sensor..."));
}
// Initialize the TFT display
tft.init();
tft.setRotation(1); // Set the rotation if needed
tft.fillScreen(TFT_BLACK); // Clear the screen to black
tft.setTextColor(TFT_WHITE, TFT_BLACK); // Set text color to white with a black background
}
void loop() {
if (mySensor.readMeasurement()) {
// Get CO2 reading and add 20
float co2_reading = mySensor.getCO2() + 20;
float temperature = mySensor.getTemperature();
float humidity = mySensor.getHumidity();
// Print measurements for debugging
Serial.print("CO2: ");
Serial.print(co2_reading);
Serial.print(" ppm, ");
Serial.print("Temperature: ");
Serial.print(temperature);
Serial.print(" °C, ");
Serial.print("Humidity: ");
Serial.print(humidity);
Serial.println(" %");
// Clear the screen for new readings
tft.fillScreen(TFT_BLACK);
// Display CO2 reading at the top center
tft.setTextColor(TFT_WHITE, TFT_BLACK); // Set text color to white with a black background
tft.setTextSize(3);
tft.setCursor(64, 50); // Adjust coordinates as needed
tft.printf("CO2: %.0fppm", co2_reading);
// Display temperature and humidity below CO2 reading
tft.setTextSize(3);
tft.setCursor(46, 100); // Adjust coordinates as needed
tft.printf("Temp: %.2f C", temperature);
tft.setCursor(18, 150); // Adjust coordinates as needed
tft.printf("Humidity: %.2f%%", humidity);
} else {
Serial.print(F("."));
}
delay(60000); // Wait for 60 seconds between measurements
}