#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
#include <math.h>
#define TFT_DC 2
#define TFT_CS 15
#define TFT_WIDTH 320
#define TFT_HEIGHT 240
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
void setup() {
tft.begin();
tft.setRotation(1);
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
}
void loop() {
while (true) {
drawCombinedSignalSmooth();
delay(100);
tft.fillRect(0, 0, tft.width(), tft.height(), ILI9341_BLACK);
}
}
void drawCombinedSignalSmooth() {
float xStart = 0; // Start x-coordinate
float xEnd = TFT_WIDTH; // End x-coordinate
float step = 0.01; // Step size for drawing
float xPrev = xStart;
float yPrev = calculateCombinedSignal(xStart);
for (float x = xStart + step; x <= xEnd; x += step) {
float yCurr = calculateCombinedSignal(x);
// Draw a line segment from previous point to current point
tft.drawLine(xPrev, yPrev, x, yCurr, ILI9341_YELLOW);
// Update previous point
xPrev = x;
yPrev = yCurr;
}
}
float calculateCombinedSignal(float x) {
float onde_P = -(1 / 0.4) * exp(-pow((x - 20), 2) / pow(8, 2));
float onde_Q = (1.4 / 0.4) * exp(-pow((x - 42), 2) / 1.5);
float onde_R = -(4 / 0.2) * exp(-pow((x - 47.35), 2) / pow(2.5, 2));
float onde_S = (1 / 0.2) * exp(-pow((x - 50.9), 2) / pow(1.5, 2));
float onde_T= -(1 / 0.3) * exp(-pow((x - 85), 2) / 80);
return (onde_P+onde_Q+onde_R+onde_S+onde_T)*6 + TFT_HEIGHT / 2+20;
}