Hi all,
I jave a particular problem with a ILI9225 display I am using.
My goal is to make a ringmeter (circular ring that counts the time back). the display is working like charm on my NanoV3.0 except when drawing arcs.
Some hardware details:
- Nano V3.0
- JLT2006A-V1 display: http://www.51tft.com/jlt2006a-v1/
- 74HC4050 level shifter between Nano and Display
Ok, the code I am using:
#include <SPI.h>
#include <TFT_22_ILI9225.h>
// **** declaration of LCD TFT variables ****
#define TFT_LED 0 // 0 if wired to +5V directly
#define TFT_RST 8
#define TFT_CS 10 // CS
#define TFT_RS 9
#define TFT_CLK 13 // SCK
#define TFT_SDI 11 // MOSI
TFT_22_ILI9225 tft = TFT_22_ILI9225(TFT_RST, TFT_RS, TFT_CS, TFT_LED, 0);
void setup(){
Serial.begin(9600);
// Turn on TFT screen
tft.begin();
tft.setOrientation(3);
tft.setBackgroundColor(COLOR_BLACK);
#define DEG2RAD 0.0174532925
// #########################################################################
// Draw a circular or elliptical arc with a defined thickness
// #########################################################################
// x,y == coords of centre of arc
// start_angle = 0 - 359
// seg_count = number of 3 degree segments to draw (120 => 360 degree arc)
// rx = x axis radius
// yx = y axis radius
// w = width (thickness) of arc in pixels
// colour = 16 bit colour value
// Note if rx and ry are the same then an arc of a circle is drawn
}
void loop() {
int w = 8;
int rx =88;
int ry = 88;
for (int n = 0; n < 5; n++) {
fillArc2(88, 110, 0, 100, rx-n*w, ry-n*w, w, 80-n*6);
}
while(1);
}
int fillArc2(int x, int y, int start_angle, int seg_count, int rx, int ry, int w, unsigned int colour)
{
byte seg = 12; // Segments are 3 degrees wide = 120 segments for 360 degrees
byte inc = 12; // Draw segments every 3 degrees, increase to 6 for segmented ring
// Calculate first pair of coordinates for segment start
float sx = cos((start_angle - 90) * DEG2RAD);
float sy = sin((start_angle - 90) * DEG2RAD);
uint16_t x0 = sx * (rx - w) + x;
uint16_t y0 = sy * (ry - w) + y;
uint16_t x1 = sx * rx + x;
uint16_t y1 = sy * ry + y;
// Draw colour blocks every inc degrees
for (int i = start_angle; i < start_angle + seg * seg_count; i += inc) {
// Calculate pair of coordinates for segment end
float sx2 = cos((i + seg - 90) * DEG2RAD);
float sy2 = sin((i + seg - 90) * DEG2RAD);
int x2 = sx2 * (rx - w) + x;
int y2 = sy2 * (ry - w) + y;
int x3 = sx2 * rx + x;
int y3 = sy2 * ry + y;
tft.fillTriangle(x0, y0, x1, y1, x2, y2, colour);
tft.fillTriangle(x1, y1, x2, y2, x3, y3, colour);
// Copy segment end to sgement start for next segment
x0 = x2;
y0 = y2;
x1 = x3;
y1 = y3;
}
}
I have tried several libraries, also not made for the ILI9225, modified them, but they all give the same annoying result. What is actually interesting is that the bottom and top of the ringis glitch-free. So, something keeps me wondering what is different in the algorhytm for the sides that this display can't handle....
I am quite out of options, and hoping someone could help me out?
Another, but very extensive way is to divide the ring in 60 blocks and switch them on and off pixel by pixel, but this is a lot of programming... ![]()
BTW, changing the orientation doesn't work either...
