#include <Adafruit_ILI9341.h>
#include <Adafruit_GFX.h>
#include <SPI.h>
#include <math.h>
#define TFT_RST 8
#define TFT_DC 9
#define TFT_CS 10
#define SUN_RADIUS 30
#define EARTH_RADIUS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC, TFT_RST);
void clearScreen() {
tft.fillScreen(ILI9341_BLACK);
}
void drawSun(int x, int y, int radius) {
tft.fillCircle(x, y, radius, ILI9341_RED); // Filled circle represents the Sun
}
void drawEarth(int sunX, int sunY, double angle) {
int earthX = sunX + int(cos(angle) * (SUN_RADIUS + 30)); // Adjust the distance from the Sun
int earthY = sunY + int(sin(angle) * (SUN_RADIUS + 30));
tft.fillCircle(earthX, earthY, EARTH_RADIUS, ILI9341_BLUE); // Filled circle represents the Earth
}
void solarSystemAnimation(int numFrames, int frameDelay) {
int sunX = tft.width() / 2;
int sunY = tft.height() / 2;
for (int i = 0; i < numFrames; i++) {
double angle = i * 1.1; // Adjust the rotation speed by changing the multiplier
clearScreen();
drawSun(sunX, sunY, SUN_RADIUS);
drawEarth(sunX, sunY, angle);
delay(frameDelay);
}
}
void setup() {
tft.begin();
tft.setRotation(3);
tft.fillScreen(ILI9341_BLACK);
clearScreen();
solarSystemAnimation(360, 1000); // Earth revolving around the Sun for a full orbit with a delay of 20 milliseconds
}
void loop() {
// Your main code (if any) goes here
}
led chasing on tft code by arvind.
अरविन्द पाटील 21/11/23 .