#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);
}
void loop() {
drawCombinedSignals();
//delay(50); // Attendre quelques secondes avant de dessiner à nouveau
//tft.fillScreen(ILI9341_BLACK); // Effacer l'écran avant de dessiner à nouveau
}
void drawCombinedSignals() {
// Définition des décalages pour chaque courbe
int offsets[] = {0, TFT_WIDTH / 3, (2 * TFT_WIDTH) / 3};
// Dessiner les trois courbes avec une seule boucle
for (int i = 0; i < 3; i++) {
int offset = offsets[i];
for (int x = i * TFT_WIDTH / 3; x < (i + 1) * TFT_WIDTH / 3 - 1; x++) {
float y1 = calculateCombinedSignal(x, offset);
float y2 = calculateCombinedSignal(x + 1, offset);
tft.drawLine(x, y1, x + 1, y2, ILI9341_YELLOW); // Utilisation de la couleur jaune pour toutes les courbes
delay(1); // Attendre quelques secondes avant de dessiner à nouveau
}
}tft.fillScreen(ILI9341_BLACK);
}
float calculateCombinedSignal(int x, int offset) {
// Calculer les composantes des signaux avec le décalage spécifié
float onde_P = -(1 / 0.4) * exp(-pow((x - 20 - offset), 2) / pow(8, 2));
float onde_Q = (1.4 / 0.4) * exp(-pow((x - 42 - offset), 2) / 1.5);
float onde_R = -(4 / 0.2) * exp(-pow((x - 47.35 - offset), 2) / pow(2.5, 2));
float onde_S = (1 / 0.2) * exp(-pow((x - 50.9 - offset), 2) / pow(1.5, 2));
float onde_T = -(1 / 0.3) * exp(-pow((x - 85 - offset), 2) / 80);
// Additionner les composantes des signaux
return (onde_P + onde_Q + onde_R + onde_S + onde_T) * 6 + TFT_HEIGHT / 2 + 20;
}