#include <SPI.h>
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include "DHT.h"
#define DHTPIN 15
#define DHTTYPE DHT22
DHT dht(DHTPIN, DHTTYPE);
#define TFT_CS 16
#define TFT_DC 5
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define LTBLUE 0xB6DF
#define LTTEAL 0xBF5F
#define LTGREEN 0xBFF7
#define LTCYAN 0xC7FF
#define LTRED 0xFD34
#define LTMAGENTA 0xFD5F
#define LTYELLOW 0xFFF8
#define LTORANGE 0xFE73
#define LTPINK 0xFDDF
#define LTPURPLE 0xCCFF
#define LTGREY 0xE71C
#define BLUE 0x001F
#define TEAL 0x0438
#define GREEN 0x07E0
#define CYAN 0x07FF
#define RED 0xF800
#define MAGENTA 0xF81F
#define YELLOW 0xFFE0
#define ORANGE 0xFC00
#define PINK 0xF81F
#define PURPLE 0x8010
#define GREY 0xC618
#define WHITE 0xFFFF
#define BLACK 0x0000
#define DKBLUE 0x000D
#define DKTEAL 0x020C
#define DKGREEN 0x03E0
#define DKCYAN 0x03EF
#define DKRED 0x6000
#define DKMAGENTA 0x8008
#define DKYELLOW 0x8400
#define DKORANGE 0x8200
#define DKPINK 0x9009
#define DKPURPLE 0x4010
#define DKGREY 0x4A49
double a1, b1, c1, d1, r2, r1, tempC, humid;
// Sine wave data array
const uint8_t sine_wave[] = {
0x80, 0x83, 0x87, 0x8A, 0x8E, 0x91, 0x95, 0x98, 0x9B, 0x9E, 0xA2, 0xA5, 0xA7, 0xAA, 0xAD, 0xAF,
0xB2, 0xB4, 0xB6, 0xB8, 0xB9, 0xBB, 0xBC, 0xBD, 0xBE, 0xBF, 0xBF, 0xBF, 0xC0, 0xBF, 0xBF, 0xBF,
0xBE, 0xBD, 0xBC, 0xBB, 0xB9, 0xB8, 0xB6, 0xB4, 0xB2, 0xAF, 0xAD, 0xAA, 0xA7, 0xA5, 0xA2, 0x9E,
0x9B, 0x98, 0x95, 0x91, 0x8E, 0x8A, 0x87, 0x83, 0x80, 0x7C, 0x78, 0x75, 0x71, 0x6E, 0x6A, 0x67,
0x64, 0x61, 0x5D, 0x5A, 0x58, 0x55, 0x52, 0x50, 0x4D, 0x4B, 0x49, 0x47, 0x46, 0x44, 0x43, 0x42,
0x41, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x41, 0x42, 0x43, 0x44, 0x46, 0x47, 0x49, 0x4B,
0x4D, 0x50, 0x52, 0x55, 0x58, 0x5A, 0x5D, 0x61, 0x64, 0x67, 0x6A, 0x6E, 0x71, 0x75, 0x78, 0x7C
};
boolean display1 = true;
double ox, oy;
double y;
int x, xmin, xmax;
void setup() {
x = 0; xmin = 0; xmax = (sizeof(sine_wave) * 3 / 2) - 1; // Adjusted for 1.5 cycles
Serial.begin(115200);
dht.begin();
tft.begin();
tft.fillScreen(BLACK);
tft.setRotation(1);
a1 = 3.354016E-03;
b1 = 2.569850E-04;
c1 = 2.620131E-06;
d1 = 6.383091E-08;
delay(1000);
}
void loop() {
// Use the sine wave data instead of reading from the DHT sensor
y = sine_wave[x % sizeof(sine_wave)]; // Adjust for looping through 1.5 cycles
if (x < xmax) {
x++;
} else {
x = 0;
display1 = true;
tft.fillScreen(BLACK);
delay(500);
}
// Adjust the width (w) parameter to make the x-axis smaller
Graph(tft, x, y, 30, 210, 270, 180, xmin, xmax, 60, 0, 255, 10, " Sine Wave", " Time [s]", "Amplitude", DKBLUE, RED, GREEN, WHITE, BLACK, display1);
Serial.print("Amplitude: "); Serial.println(y);
delay(100);
}
void Graph(Adafruit_ILI9341 &d, double x, double y, double gx, double gy, double w, double h, double xlo, double xhi, double xinc, double ylo, double yhi, double yinc, String title, String xlabel, String ylabel, unsigned int gcolor, unsigned int acolor, unsigned int pcolor, unsigned int tcolor, unsigned int bcolor, boolean &redraw) {
double ydiv, xdiv;
double i;
double temp;
if (redraw == true) {
redraw = false;
ox = (x - xlo) * (w) / (xhi - xlo) + gx;
oy = (y - ylo) * (gy - h - gy) / (yhi - ylo) + gy;
// y-axis labels with default spacing
for (i = ylo; i <= yhi; i += yinc) {
temp = (i - ylo) * (gy - h - gy) / (yhi - ylo) + gy;
if (i == 0) {
d.drawLine(gx, temp, gx + w, temp, acolor);
} else {
d.drawLine(gx, temp, gx + w, temp, gcolor);
}
d.setTextSize(1);
d.setTextColor(tcolor, bcolor);
d.setCursor(gx - 20, temp - 5);
int ay = i;
d.println(ay);
}
// x-axis labels with adjusted spacing
int xLabels[] = {0, 60, 70, 80, 90, 100, 110, 120};
double xPos;
for (int j = 0; j < sizeof(xLabels) / sizeof(xLabels[0]); j++) {
if (xLabels[j] == 0) {
xPos = gx;
} else if (xLabels[j] == 60) {
xPos = gx + 0.1 * w; // Adjust the position of 60
} else {
xPos = gx + (0.1 + (xLabels[j] - 60) / 60.0 * 0.9) * w; // Adjust positions for other labels
}
if (xLabels[j] == 0) {
d.drawLine(xPos, gy, xPos, gy - h, acolor);
} else {
d.drawLine(xPos, gy, xPos, gy - h, gcolor);
}
d.setTextSize(1);
d.setTextColor(tcolor, bcolor);
d.setCursor(xPos - 10, gy + 10);
d.println(xLabels[j]);
}
d.setTextSize(2);
d.setTextColor(tcolor, bcolor);
d.setCursor(gx , gy - h - 30);
d.println(title);
d.setTextSize(1);
d.setTextColor(acolor, bcolor);
d.setCursor(gx , gy + 20);
d.println(xlabel);
d.setTextSize(1);
d.setTextColor(acolor, bcolor);
d.setCursor(gx - 50, gy - h);
d.println(ylabel);
}
d.setTextColor(pcolor, bcolor);
d.drawLine(ox, oy, (x - xlo) * (w) / (xhi - xlo) + gx, (y - ylo) * (gy - h - gy) / (yhi - ylo) + gy, pcolor);
ox = (x - xlo) * (w) / (xhi - xlo) + gx;
oy = (y - ylo) * (gy - h - gy) / (yhi - ylo) + gy;
}