#include <Adafruit_GFX.h>
#include <Adafruit_ILI9341.h>
#include <SPI.h>
#define TFT_CS 2
#define TFT_RST 4
#define TFT_DC 5
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
int mapValue(float value, float fromLow, float fromHigh, float toLow, float toHigh) {
return int((value - fromLow) * (toHigh - toLow) / (fromHigh - fromLow) + toLow);
}
void drawSineWave() {
const int LCD_WIDTH = tft.width();
const int LCD_HEIGHT = tft.height();
tft.fillScreen(ILI9341_BLACK);
tft.setTextColor(ILI9341_WHITE);
tft.setTextSize(2);
for (int x = 0; x < LCD_WIDTH; x++) {
float radians = (x / float(LCD_WIDTH)) * TWO_PI;
float sineValue = sin(radians);
int y = mapValue(sineValue, -1, 1, 0, LCD_HEIGHT);
tft.drawPixel(x, y, ILI9341_WHITE);
}
tft.setCursor(0, 0);
tft.print("Sine Wave");
}
void setup() {
tft.begin();
tft.setRotation(3);
drawSineWave();
}
void loop() {
}