Wrote a little program that can draw from the Serial window,
clr(255,255,255) clears screen
setColor( 0 , 0 , 0 ) to setColor( 255 , 255 , 255 )
arc( posX , posY , size , lineThickness , startCircle , endcircle )
ie. arc( 100 , 100 , 50 , 1 , 40 , 360 )
will add more, text(), squ() etc..
#include <SPI.h>
#include <ILI_SdSpi.h>
#include <ILI_SdFatConfig.h>
#include <ILI9341_due_gText.h>
#include <ILI9341_due.h>
#include "fonts\Arial_bold_14.h"
#define TFT_DC 9
#define TFT_CS 10
ILI9341_due tft = ILI9341_due(TFT_CS, TFT_DC);
char textBuff[20];
char charTemp[20];
int color[3];
ILI9341_due_gText t1(&tft);
ILI9341_due_gText t2(&tft);
ILI9341_due_gText t3(&tft);
uint16_t colorLightGray = tft.color565(192,192,192);
uint16_t colorGray = tft.color565(127,127,127);
uint16_t colorDarkGray = tft.color565(64,64,64);
// Globals
uint16_t radius = 55;
uint16_t s1x = 0;
uint16_t s1y = 10;
int myDelay = 2000;
void setup() {
Serial.begin(9600);
tft.begin();
tft.setRotation(3);
delay(500);
screenLoading();
while(!Serial.available()){
Serial.println(F("Enter any key to begin"));
screenLoading();
delay(2000);
}
}
void loop() {
if( Serial.available() >0 ){
String str="";
while(Serial.available()>0){
str += char(Serial.read());
}
serialInput( str );
Serial.println();
}
}
void screenLoading(){
const uint16_t x = 159;
const uint16_t y = 149;
tft.fillScreen(ILI9341_BLACK);
t1.selectFont(roboto32);
t1.setFontLetterSpacing(5);
t1.setFontColor(ILI9341_WHITE, ILI9341_BLACK);
t1.defineArea(100, 85, 220, 140);
strcpy(textBuff, "Loading...");
t1.drawString(textBuff, gTextAlignTopCenter, 0, 0);
tft.drawArc(x, y, 10, 5, 0, 360, colorLightGray);
for(int i=0; i<2880; i+=4){
tft.drawArc(x, y, 10, 5, (i >> 1)-45, (i >> 1)+45, colorDarkGray);
tft.drawArc(x, y, 10, 5, (i >> 1)-45-4, (i >> 1)-45, colorLightGray);
tft.drawArc(x, y, 20, 5, 1440-i-45, 1440-i+45, colorDarkGray);
tft.drawArc(x, y, 20, 5, 1440-i+45, 1440-i+45+4, colorLightGray);
}
}
void serialInput( String str ){
int command = getCommandAsInt( str );
String variables = getDataAsString( str );
switch( command ){
case 321: // clr=321
clrScreen( variables );
break;
case 310: // clr=321
arc( variables );
break;
case 843: // clr=321
getColorData( variables );
break;
default:
Serial.println( command );
}
}
String getDataAsString( String str ){
int myStart = str.indexOf('(');
int myEnd = str.indexOf(')');
if(myStart==-1)
return "";
return str.substring( myStart+1 , myEnd );
}
int getCommandAsInt( String str ){
// convert a String value to a int ie abc a+b+c
int endCommandLetter = str.indexOf('(');
int stringValue=0;
if(endCommandLetter==-1)
endCommandLetter=str.length();
for(int i=0;i<endCommandLetter;i++){
stringValue+=str.charAt(i);
}
return stringValue;
}
int getDataCount( String str ){
String strTemp = str.substring( str.indexOf('(')+1 , str.indexOf(')') );
return findOutHowManyCharInAString( strTemp , ',' );
}
int findOutHowManyCharInAString(String str, char findChar){
int positionChar = 0, count=0;
while(positionChar != -1){
positionChar = str.indexOf( findChar , positionChar+1 );
if(positionChar!=-1)
count++;
}
return count;
}
int stringToInt(String thisString) {
int i, value, length;
length = thisString.length();
char blah[(length+1)];
for(i=0; i<length; i++) {
blah[i] = thisString.charAt(i);
}
blah[i]=0;
value = atoi(blah);
return value;
}
void setCharTemp( String str ){
String strTemp = str.substring( str.indexOf('(')+1 , str.indexOf(')') );
strTemp.toCharArray( textBuff , 20 );
}
int getIntData( String str ){
int value = stringToInt( str.substring( str.indexOf('(')+1 , str.indexOf(')') ));
if(value==0)
return myDelay;
else
return value;
}
String getStringData( String str ){
int myStart = str.indexOf('(');
int myEnd = str.indexOf(')');
return str.substring( myStart+1 , myEnd );
}
void clrScreen( String str ){
if(str.length()>0){
boolean isColor = getColorData( str );
uint16_t myColor = tft.color565(color[0],color[1],color[2]);
tft.fillScreen( myColor );
}
else
Serial.println("clr(r,g,b) ie clr( 255 , 255 , 255 ) ");
}
boolean getColorData( String str ){
int myLength = str.length();
if(myLength>0){
color[0] = stringToInt( str.substring(0 , str.indexOf( ',' )));
color[1] = stringToInt( str.substring(str.indexOf( ',' )+1 , str.lastIndexOf( ',' )));
color[2] = stringToInt( str.substring(str.lastIndexOf( ',' )+1 , myLength ));
}
else
return 0;
}
void arc(String str){
Serial.println( str );
Serial.println(findOutHowManyCharInAString( str , ',' )+1);
int x=stringToInt( str.substring( 0 , str.indexOf(',')));
str = str.substring( str.indexOf(',')+1 , str.length() );
int y=stringToInt( str.substring( 0 , str.indexOf(',')));
str = str.substring( str.indexOf(',')+1 , str.length() );
int sizeC=stringToInt( str.substring( 0 , str.indexOf(',')));
str = str.substring( str.indexOf(',')+1 , str.length() );
int thickness=stringToInt( str.substring( 0 , str.indexOf(',')));
str = str.substring( str.indexOf(',')+1 , str.length() );
int startC=stringToInt( str.substring( 0 , str.indexOf(',')));
str = str.substring( str.indexOf(',')+1 , str.length() );
int endC=stringToInt( str.substring( 0 , str.indexOf(',')));
str = str.substring( str.indexOf(',')+1 , str.length() );
Serial.println( str );
uint16_t myColor = tft.color565(color[0],color[1],color[2]);
tft.drawArc(x, y, sizeC, thickness, startC, endC, myColor);
}