#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 s2 = 0;
int offset = 1;
while (true) { // Boucle infinie
float y1 = -(3.5/ 0.25) * exp(-pow((x - 15-offset), 2) / pow(4, 2));
float y2 = (7) * exp(-pow((x - 20-offset), 2) / pow(8, 2));
float y3 = -(2) * exp(-pow((x -20.2-offset), 2) / pow(6, 2));
s2+=y1+y2+y3; offset += 100;
// Sortir de la boucle si nécessaire
if (offset > 1000) {
break; // Sortir de la boucle infinie lorsque offset dépasse 900
}
}
return 0.4 *s2* 10 + TFT_HEIGHT / 2; // Scale and shift the result for display
}