// Demo using arcFill to draw ellipses and a segmented elipse
//#include <TFT_eSPI.h> // Hardware-specific library
#include "Adafruit_GFX.h"
#include "Adafruit_ILI9341.h"
#include <SPI.h>
//TFT_eSPI tft = TFT_eSPI(); // Invoke custom library
#define TFT_DC 21
#define TFT_CS 22
Adafruit_ILI9341 tft = Adafruit_ILI9341(TFT_CS, TFT_DC);
#define DEG2RAD 0.0174532925
#define LOOP_DELAY 10 // Loop delay to slow things down
#define ENCODER_CLK 14
#define ENCODER_DT 12
#define ENCODER_SW 13
#define RED2RED 0
#define GREEN2GREEN 1
#define BLUE2BLUE 2
#define BLUE2RED 3
#define GREEN2RED 4
#define RED2GREEN 5
int counter = 0;
byte inc = 0;
unsigned int col = 0;
byte red = 31; // Red is the top 5 bits of a 16 bit colour value
byte green = 0;// Green is the middle 6 bits
byte blue = 0; // Blue is the bottom 5 bits
byte state = 0;
int tempValue = 0;
void setup(void) {
tft.begin();
tft.setRotation(1);
// tft.fillScreen(TFT_BLACK);
tft.fillScreen(ILI9341_BLACK);
}
void loop() {
int x = tft.width() / 2;
int y = tft.height() / 2;
int radius = 50;
int start = 45;
int end = 135;
int color = ILI9341_GREEN;
int thickness = 10;
//tft.fillCircle(x, y, radius, color);
//tft.drawCircle(x, y, radius, ILI9341_DARKGREEN);
drawArc(x, y, radius, thickness, start, end, ILI9341_DARKGREEN);
//fillArc(x, y, radius - thickness, start, end, color);
}
void drawArc(int x, int y, int radius, int w, int start, int end, int color) {
int x1, y1, x2, y2;
float angle;
int j = 0;
for (int i = start; i <= end; i++) {
angle = i * 0.0174532925;
x1 = x + (radius * cos(angle));
y1 = y + (radius * sin(angle));
x2 = x + (radius - w * cos(angle));
y2 = y + (radius - w * sin(angle));
if (i == start || i == end) {
tft.drawLine(x1, y1, x2, y2, color);
}
tft.drawPixel(x1, y1, color);
tft.drawPixel(x2, y2, color);
}
}
void fillArc(int x, int y, int radius, int start, int end, int color) {
int x1, y1, x2, y2;
float angle;
for (int i = start; i < end; i++) {
angle = i * 0.0174532925;
x1 = x + (radius * cos(angle));
y1 = y + (radius * sin(angle));
x2 = x + ((radius - 1) * cos(angle));
y2 = y + ((radius - 1) * sin(angle));
tft.drawLine(x1, y1, x2, y2, color);
}
}