/*
Simple "Hello World" for ILI9341 LCD
https://wokwi.com/arduino/projects/308024602434470466
*/
#include "SPI.h"
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#define TFT_DC 9
#define TFT_CS 10
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define PI 3.1415926535897932384626433832795
int n, f;
int j, j2;
int i, i2;
uint16_t col[5] = {0x7006, 0xF986, 0x6905, 0x7FF7, 0x024D};
void setup() {
tft.begin();
delay(100);
tft.setRotation(1);
//tft.setCursor(20, 160);
tft.setTextColor(ILI9341_GREEN);
tft.setTextSize(2);
tft.println("I can has colors?");
tft.drawRect(0,0,128,64,col[1]);
// Meme reference: https://english.stackexchange.com/questions/20356/origin-of-i-can-haz
/*
for (int p = 0; p < 400; p++) {
j = 150 * (sin(PI * p / 400));
i = 150 * (cos(PI * p / 400));
j2 = 155 * (sin(PI * p / 400));
i2 = 155 * (cos(PI * p / 400));
tft.drawLine(i2 + 240, j2 + 170, i + 240, j + 170, col[n]);
}
*/
/*
for (int p = 0; p < 80; p++) {
j = 140 * (sin(PI * p / 40));
i = 140 * (cos(PI * p / 40));
tft.drawPixel(i + 240, j + 170, col[4]);
}
for (int p = 0; p < 80; p++) {
j = 144 * (sin(PI * p / 40));
i = 144 * (cos(PI * p / 40));
tft.drawPixel(i + 240, j + 170, col[1]);
}
for (int p = 0; p < 20; p++) {
j = 142 * (sin(PI * p / 20));
i = 142 * (cos(PI * p / 20));
tft.drawLine(i2 + 240, j2 + 170, i + 240, j + 170, col[n]);
j2=j;
i2=i;
}
*/
/*
for (int p = 0; p < 80; p++) {
j = 144 * (sin(PI * p / 80));
i = 144 * (cos(PI * p / 80));
//tft.drawPixel(i + 240, j + 170, col[1]);
tft.fillRoundRect(i + 240, j + 170, 5, 5, 2, col[1]);
}
*/
/*
tft.setTextSize(1);
for (int p = 100; p < 300; p++)
{ j = 145 * (sin(PI * p / 13));
i = 145 * (cos(PI * p / 13));
tft.setCursor(i+240, j+170);
tft.write(p);
}
*/
//AngleArc(240, 170, 120, 180, 180, col[1]);
/*
AngleArc(100, 100, 100, 90, 45, col[2]);
AngleArc(100, 100, 100, 180, 45, col[3]);
AngleArc(100, 100, 100, 270, 45, col[4]);
*/
for (int p = 40; p < 80; p++) {
j = 144 * (sin(PI * p / 40));
i = 144 * (cos(PI * p / 40));
tft.drawPixel(i + 150, j +170, col[1]);
}
tft.setTextSize(1);
int speed=20;
for (int p = 14; p < 27; p++) {
j = 135 * (sin(PI * p / 13));
i = 135 * (cos(PI * p / 13));
tft.setCursor(i+150, j+220);
tft.print(speed);
speed = speed+10;
}
}
void loop() { }
int16_t get_angle(int16_t centerX, int16_t centerY, int16_t pointX, int16_t pointY){
int16_t x = pointX - centerX;
int16_t y = pointY - centerY;
if(x==0) return (y>0) ? 180 : 0;
int16_t a = atan2(y, x)*180/PI;
a += 90;
if ((x < 0) && (y < 0)) a+=360;
return a;
}
void AngleArc(int16_t _x, int16_t _y, int16_t r, int16_t startAngle, int16_t sweepAngle, uint16_t color) {
startAngle = abs(startAngle);
sweepAngle = abs(sweepAngle);
if (startAngle >= 360) startAngle = 0;
if (sweepAngle > 360) sweepAngle = 360;
if (startAngle + sweepAngle > 360) {
AngleArc(_x, _y, r, 0, startAngle + sweepAngle - 360, color);
sweepAngle = 360 - startAngle;
}
int16_t x = 0;
int16_t y = r;
int16_t gap = 0;
int16_t delta = (2 - 2 * r);
int16_t angle;
while (y >= 0) {
angle = get_angle(_x, _y, _x + x, _y - y);
if ((angle >= startAngle) && (angle <= startAngle + sweepAngle)) {
if (0<=angle<=90) tft.drawPixel(_x + x, _y - y, color);
}
angle = get_angle(_x, _y, _x + x, _y + y);
if ((angle >= startAngle) && (angle <= startAngle + sweepAngle)) {
if (90<angle<=180) tft.drawPixel(_x + x, _y + y, color);
}
angle = get_angle(_x, _y, _x - x, _y + y);
if ((angle >= startAngle) && (angle <= startAngle + sweepAngle)) {
if (180<angle<=270) tft.drawPixel(_x - x, _y + y, color);
}
angle = get_angle(_x, _y, _x - x, _y - y);
if ((angle >= startAngle) && (angle <= startAngle + sweepAngle)) {
if (270<angle<=360) tft.drawPixel(_x - x, _y - y, color);
}
gap = 2 * (delta + y) - 1;
if (delta < 0 && gap <= 0) {
x++;
delta += 2 * x + 1;
continue;
}
if (delta > 0 && gap > 0) {
y--;
delta -= 2 * y + 1;
continue;
}
x++;
delta += 2 * (x - y);
y--;
}
}