#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) {
drawCombinedSignals();
delay(100);
tft.fillRect(0, 0, tft.width(), tft.height(), ILI9341_BLACK);
}
}
void drawCombinedSignals() {
int startX = 0; // Position de départ de la courbe
while (startX < TFT_WIDTH) {
tft.fillScreen(ILI9341_BLACK); // Effacer l'écran après chaque itération
int x = startX;
for (; x < TFT_WIDTH - 1; x++) {
float y1 = calculateCombinedSignal(x);
float y2 = calculateCombinedSignal(x + 1);
tft.drawLine(x, y1, x + 1, y2, ILI9341_YELLOW);}
}}
float calculateCombinedSignal(float x) {
float s3 = 0;
int offset = 1;
while (true) { // Boucle infinie
float y1 = -(0.4 / 2.5) * exp(-pow((x - 12-offset), 2) / pow(6, 2));
float y2 = -(0.5 / 5) * exp(-pow((x - 25.5-offset), 2) / pow(3, 2));
float y3 = -(0.4 / 5) * exp(-pow((x - 35-offset), 2) / pow(2, 2));
float y4 = (0.7 / 5) * exp(-pow((x - 40-offset), 2) / pow(2, 2));
float y5 = -(0.6 / 9) * exp(-pow((x - 50-offset), 2) / 15);
float y6 = -(0.7 / 3.0) * exp(-pow((x - 60-offset), 2) / pow(12, 2));
s3+=y1 - y2 + y3 + y4 + y5 + y6;
offset += 90;
// Sortir de la boucle si nécessaire
if (offset > 1000) {
break; // Sortir de la boucle infinie lorsque offset dépasse 900
}
}
return (s3) * 15 + TFT_HEIGHT / 2;
}