From 6614f7e15ca8d5219ca3bb91d9ad8170deac664b Mon Sep 17 00:00:00 2001 From: KAbhijeet2105 Date: Sun, 29 Mar 2020 15:17:25 +0530 Subject: [PATCH 1/6] Added new examples --- examples/Arduino/TFTCircle/TFTCircle.ino | 56 ++++++++ examples/Arduino/TFTLine/TFTLine.ino | 70 ++++++++++ .../Arduino/TFTPointLine/TFTPointLine.ino | 100 ++++++++++++++ examples/Arduino/TFTRect/TFTRect.ino | 60 +++++++++ .../Arduino/TFTStorageRead/TFTStorageRead.ino | 127 ++++++++++++++++++ examples/Arduino/TFTUserText/TFTUserText.ino | 57 ++++++++ 6 files changed, 470 insertions(+) create mode 100644 examples/Arduino/TFTCircle/TFTCircle.ino create mode 100644 examples/Arduino/TFTLine/TFTLine.ino create mode 100644 examples/Arduino/TFTPointLine/TFTPointLine.ino create mode 100644 examples/Arduino/TFTRect/TFTRect.ino create mode 100644 examples/Arduino/TFTStorageRead/TFTStorageRead.ino create mode 100644 examples/Arduino/TFTUserText/TFTUserText.ino diff --git a/examples/Arduino/TFTCircle/TFTCircle.ino b/examples/Arduino/TFTCircle/TFTCircle.ino new file mode 100644 index 0000000..5629223 --- /dev/null +++ b/examples/Arduino/TFTCircle/TFTCircle.ino @@ -0,0 +1,56 @@ +/* TFTCircle + + by K.Abhijeet + + This example code takes input radius from serial and prints the circle to the screen. +*/ + +#include // Arduino LCD library +#include + + +// pin definition for the Uno +#define cs 10 +#define dc 9 +#define rst 8 + +// pin definition for the Leonardo +// #define cs 7 +// #define dc 0 +// #define rst 1 + +// create an instance of the library +TFT TFTscreen = TFT(cs, dc, rst); + + + +int red; + +void setup() { + + Serial.begin(9600); + + // Put this line at the beginning of every sketch that uses the GLCD: + TFTscreen.begin(); + + // clear the screen with a black background + TFTscreen.background(0, 0, 0); + + // set the font color to white + TFTscreen.stroke(255, 255, 255); + + // write the static text to the screen + Serial.println("Enter radius :"); + //waiting for input + while (Serial.available() == 0) {} + red = Serial.parseInt(); + + + TFTscreen.setTextSize(1); + TFTscreen.text("Your circle : ", 2, 0); + + TFTscreen.fill(255, 255, 0); + TFTscreen.circle( TFTscreen.width()/2, TFTscreen.height()/2, red); // draw circle +} + +void loop() {} diff --git a/examples/Arduino/TFTLine/TFTLine.ino b/examples/Arduino/TFTLine/TFTLine.ino new file mode 100644 index 0000000..7d8cb12 --- /dev/null +++ b/examples/Arduino/TFTLine/TFTLine.ino @@ -0,0 +1,70 @@ +/* TFTLine + + by K.Abhijeet + This example code takes input x1,y1(Initial co-ordinates to draw line) and x2,y2(end co-ordinates to draw line) from serial and prints the line to the screen. +*/ + +#include // Arduino LCD library +#include + + +// pin definition for the Uno +#define cs 10 +#define dc 9 +#define rst 8 + +// pin definition for the Leonardo +// #define cs 7 +// #define dc 0 +// #define rst 1 + +// create an instance of the library +TFT TFTscreen = TFT(cs, dc, rst); +int x1, y1, x2, y2; + + +void setup() { + + Serial.begin(9600); + + // Put this line at the beginning of every sketch that uses the GLCD: + TFTscreen.begin(); + + // clear the screen with a black background + TFTscreen.background(0, 0, 0); + + // set the font color to white + TFTscreen.stroke(255, 255, 255); + + // write the static text to the screen + Serial.println("Enter x1 :"); + //waiting for input + while (Serial.available() == 0) {} + x1 = Serial.parseInt(); + + // write the static text to the screen + Serial.println("Enter y1 :"); + //waiting for input + while (Serial.available() == 0) {} + y1 = Serial.parseInt(); + + // write the static text to the screen + Serial.println("Enter x2 :"); + //waiting for input + while (Serial.available() == 0) {} + x2 = Serial.parseInt(); + + // write the static text to the screen + Serial.println("Enter y2 :"); + //waiting for input + while (Serial.available() == 0) {} + y2 = Serial.parseInt(); + + TFTscreen.setTextSize(1); + TFTscreen.text("Your Line : ", 2, 0); + + TFTscreen.line(x1, y1, x2, y2); + +} + +void loop() {} diff --git a/examples/Arduino/TFTPointLine/TFTPointLine.ino b/examples/Arduino/TFTPointLine/TFTPointLine.ino new file mode 100644 index 0000000..2d95dc1 --- /dev/null +++ b/examples/Arduino/TFTPointLine/TFTPointLine.ino @@ -0,0 +1,100 @@ +/* TFTPointLine + + by K.Abhijeet + This example code takes input x1,y1(Initial co-ordinates to draw line) and x2,y2(end co-ordinates to draw line) from serial and prints the line to the screen + by using bresenham’s line drawing algorithm. +*/ + +#include // Arduino LCD library +#include + +// pin definition for the Uno +#define cs 10 +#define dc 9 +#define rst 8 + +// pin definition for the Leonardo +// #define cs 7 +// #define dc 0 +// #define rst 1 + +// create an instance of the library +TFT TFTscreen = TFT(cs, dc, rst); +int x1, y1, x2, y2; +float m, b; +void setup() { + + Serial.begin(9600); + + // Put this line at the beginning of every sketch that uses the GLCD: + TFTscreen.begin(); + + // clear the screen with a black background + TFTscreen.background(0, 0, 0); + + // set the font color to white + TFTscreen.stroke(255, 255, 255); + + // write the static text to the screen + Serial.println("Enter x1 :"); + //waiting for input + while (Serial.available() == 0) {} + x1 = Serial.parseInt(); + + // write the static text to the screen + Serial.println("Enter y1 :"); + //waiting for input + while (Serial.available() == 0) {} + y1 = Serial.parseInt(); + + // write the static text to the screen + Serial.println("Enter x2 :"); + //waiting for input + while (Serial.available() == 0) {} + x2 = Serial.parseInt(); + + // write the static text to the screen + Serial.println("Enter y2 :"); + //waiting for input + while (Serial.available() == 0) {} + y2 = Serial.parseInt(); + + TFTscreen.setTextSize(1); + TFTscreen.text("Your Line : ", 2, 0); + + drawline(x1, y1, x2, y2); + +} + +void loop() {} + +void drawline(int x0, int y0, int x1, int y1) +{ + int dx, dy, p, x, y; + + dx = x1 - x0; + dy = y1 - y0; + + x = x0; + y = y0; + + p = 2 * dy - dx; + + while (x < x1) + { + if (p >= 0) + { + delay(100); + TFTscreen.point(x, y); + y = y + 1; + p = p + 2 * dy - 2 * dx; + } + else + { + delay(100); + TFTscreen.point(x, y); + p = p + 2 * dy; + } + x = x + 1; + } +} diff --git a/examples/Arduino/TFTRect/TFTRect.ino b/examples/Arduino/TFTRect/TFTRect.ino new file mode 100644 index 0000000..c764a27 --- /dev/null +++ b/examples/Arduino/TFTRect/TFTRect.ino @@ -0,0 +1,60 @@ +/* TFTRect + + by K.Abhijeet + + This example code takes input length and width from serial and prints the rectangle to the screen. +*/ + +#include // Arduino LCD library +#include + + +// pin definition for the Uno +#define cs 10 +#define dc 9 +#define rst 8 + +// pin definition for the Leonardo +// #define cs 7 +// #define dc 0 +// #define rst 1 + +// create an instance of the library +TFT TFTscreen = TFT(cs, dc, rst); + +// char array to print to the screen + +int len, wid; + +void setup() { + + Serial.begin(9600); + + // Put this line at the beginning of every sketch that uses the GLCD: + TFTscreen.begin(); + + // clear the screen with a black background + TFTscreen.background(0, 0, 0); + + // set the font color to white + TFTscreen.stroke(255, 255, 255); + + // write the static text to the screen + Serial.println("Enter length :"); + //waiting for input + while (Serial.available() == 0) {} + len = Serial.parseInt(); + + Serial.println("Enter width :"); + //waiting for input + while (Serial.available() == 0) {} + wid = Serial.parseInt(); + + TFTscreen.setTextSize(1); + TFTscreen.text("Your Rectangle : ", 2, 0); + + TFTscreen.fill(255, 255, 0); + TFTscreen.rect(10, 20, len, wid); // draw rectangle +} + +void loop() {} diff --git a/examples/Arduino/TFTStorageRead/TFTStorageRead.ino b/examples/Arduino/TFTStorageRead/TFTStorageRead.ino new file mode 100644 index 0000000..ee86585 --- /dev/null +++ b/examples/Arduino/TFTStorageRead/TFTStorageRead.ino @@ -0,0 +1,127 @@ +/* + TFTStorageRead + + This example shows how to read data from an SD card file and prints it to the screen. + + The circuit: + SD card attached to SPI bus as follows: + ** MOSI - pin 11 + ** MISO - pin 12 + ** CLK - pin 13 + ** CS - pin 4 (for MKRZero SD: SDCARD_SS_PIN) + + TFT Screen attached to SPI bus as follows: + cs - pin 10 + dc - pin 9 + rst - pin 8 + + created by Abhijeet Kadam + This example code is in the public domain. + +*/ + +// pin definition for the Uno +#define cs 10 +#define dc 9 +#define rst 8 + + +#include // Arduino LCD library +#include +#include + +String fname; +int n = 0; +File root, myFile; +char str[100];// char array to print to the screen + +// create an instance of the library +TFT TFTscreen = TFT(cs, dc, rst); + +void setup() { + // Open serial communications and wait for port to open: + Serial.begin(9600); + while (!Serial) { + ; // wait for serial port to connect. Needed for native USB port only + } + + Serial.print("Initializing SD card..."); + + if (!SD.begin(4)) { + Serial.println("initialization failed!"); + while (1); + } + Serial.println("initialization done."); + + // Put this line at the beginning of every sketch that uses the GLCD: + TFTscreen.begin(); + + // clear the screen with a black background + TFTscreen.background(0, 0, 0); + + // set the font color to white + TFTscreen.stroke(255, 255, 255); + // set the font size + + root = SD.open("/"); // create root reference. + printDirectory(root, 0); // print directory and file list + + Serial.println("Enter file name to read file data:");//ask user for file name eg. test.txt + waitip(); + fname = Serial.readString(); + fname.trim(); + + if (SD.exists(fname)) { //if file already exists + + myFile = SD.open(fname); + if (myFile) { + Serial.println(" " + fname); + // read from the file until there's nothing else in it: + n = 0; + while (myFile.available()) { + str[n] = myFile.read(); + n++; + } + // close the file: + myFile.close(); + TFTscreen.text(str, 0, 0); + } + } + else { //if file not exists show the message + Serial.println(fname + " doesn't exist."); + } +} + +void loop() { +} + +void waitip()// wait for user input +{ + while (Serial.available() == 0) + {} +} + +void printDirectory(File dir, int numTabs) // prints directory list +{ + while (true) { + + File entry = dir.openNextFile(); + if (! entry) { + // no more files + break; + } + for (uint8_t i = 0; i < numTabs; i++) { + Serial.print('\t'); + } + Serial.print(entry.name()); + if (entry.isDirectory()) { + Serial.println("/"); + printDirectory(entry, numTabs + 1); + } else { + // files have sizes, directories do not + Serial.print("\t\t"); + Serial.println(entry.size(), DEC); + } + entry.close(); + } +} diff --git a/examples/Arduino/TFTUserText/TFTUserText.ino b/examples/Arduino/TFTUserText/TFTUserText.ino new file mode 100644 index 0000000..eb5eb89 --- /dev/null +++ b/examples/Arduino/TFTUserText/TFTUserText.ino @@ -0,0 +1,57 @@ +/* UserText + + by K.Abhijeet + + This example code takes input username from serial and prints to the screen. +*/ + +#include // Arduino LCD library +#include + +// pin definition for the Uno +#define cs 10 +#define dc 9 +#define rst 8 + +// pin definition for the Leonardo +// #define cs 7 +// #define dc 0 +// #define rst 1 + +// create an instance of the library +TFT TFTscreen = TFT(cs, dc, rst); + +// char array to print to the screen +String nm; +char str[100]; + +void setup() { + + Serial.begin(9600); + + // Put this line at the beginning of every sketch that uses the GLCD: + TFTscreen.begin(); + + // clear the screen with a black background + TFTscreen.background(0, 0, 0); + + // set the font color to white + TFTscreen.stroke(255, 255, 255); + // set the font size + + // write the static text to the screen + Serial.println("Enter your name :"); + TFTscreen.setTextSize(1); + TFTscreen.text("Enter your name :\n ", 2, 2); + //waiting for input + while (Serial.available() == 0) {} + nm = Serial.readString(); // take input from serial + nm = "Hello " + nm; + // convert the string to a char array + nm.toCharArray(str, 100); + //print the name + TFTscreen.text(str, 0, 20); + +} + +void loop() {} From afc1704fdfa2070eaaa0faec4aa179c9ff6646ea Mon Sep 17 00:00:00 2001 From: KAbhijeet2105 Date: Mon, 30 Mar 2020 10:13:18 +0530 Subject: [PATCH 2/6] Enhancement: added a new feature to draw an arc. Added new example TFTArc:draws an arc on the screen --- examples/Arduino/TFTArc/TFTArc.ino | 75 ++++++++++++++++++++++++++++++ src/utility/Adafruit_GFX.cpp | 36 +++++++++++++- src/utility/Adafruit_GFX.h | 9 ++-- src/utility/Adafruit_ST7735.h | 1 + src/utility/keywords.txt | 2 + 5 files changed, 118 insertions(+), 5 deletions(-) create mode 100644 examples/Arduino/TFTArc/TFTArc.ino diff --git a/examples/Arduino/TFTArc/TFTArc.ino b/examples/Arduino/TFTArc/TFTArc.ino new file mode 100644 index 0000000..3e392fb --- /dev/null +++ b/examples/Arduino/TFTArc/TFTArc.ino @@ -0,0 +1,75 @@ +/* TFTArc + by K.Abhijeet + This example code takes input x,y(center co-ordinatesof arc ),r(radious),start angle,end angle from serial and prints the arc to the screen. +*/ + +#include // Arduino LCD library +#include + +// pin definition for the Uno +#define cs 10 +#define dc 9 +#define rst 8 + + +// pin definition for the Leonardo +// #define cs 7 +// #define dc 0 +// #define rst 1 + +// create an instance of the library +TFT TFTscreen = TFT(cs, dc, rst); +int16_t x, y, r, st_angle, end_angle; + +void setup() { + + Serial.begin(9600); + + // Put this line at the beginning of every sketch that uses the GLCD: + TFTscreen.begin(); + + // clear the screen with a black background + TFTscreen.background(0, 0, 0); + + // set the font color to white + TFTscreen.stroke(255, 255, 255); + + // write the static text to the screen + Serial.println("Enter x :"); + //waiting for input + while (Serial.available() == 0) {} + x = Serial.parseInt(); + + // write the static text to the screen + Serial.println("Enter y :"); + //waiting for input + while (Serial.available() == 0) {} + y = Serial.parseInt(); + + // write the static text to the screen + Serial.println("Enter r :"); + //waiting for input + while (Serial.available() == 0) {} + r = Serial.parseInt(); + + // write the static text to the screen + Serial.println("Enter start angle :"); + //waiting for input + while (Serial.available() == 0) {} + st_angle = Serial.parseInt(); + + + // write the static text to the screen + Serial.println("Enter end angle :"); + //waiting for input + while (Serial.available() == 0) {} + end_angle = Serial.parseInt(); + + + TFTscreen.setTextSize(1); + TFTscreen.text("Your Arc: ", 2, 0); + + TFTscreen.arc(x, y, r, st_angle, end_angle); //draw arc +} + +void loop() {} diff --git a/src/utility/Adafruit_GFX.cpp b/src/utility/Adafruit_GFX.cpp index 4176f11..9b584ad 100644 --- a/src/utility/Adafruit_GFX.cpp +++ b/src/utility/Adafruit_GFX.cpp @@ -160,7 +160,7 @@ void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, } } -// Bresenham's algorithm - thx wikipedia +// Bresenham's algorithm - thx wikpedia void Adafruit_GFX::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) @@ -655,6 +655,40 @@ void Adafruit_GFX::triangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int1 } } +// draw a arc outline +void Adafruit_GFX::drawArc(int16_t x, int16_t y, int16_t r, int16_t st_angle, int16_t end_angle,uint16_t color) +{ + + float angle; +float range; +float h; +float k; + angle=(((st_angle<=end_angle)?st_angle:end_angle)*(PI/180)); + range=(((end_angle>st_angle)?end_angle:st_angle)*(PI/180)); + + h=(r*cos(angle)); + k=(r*sin(angle)); + + do { + drawPixel((int16_t)(x+h+0.5),(int16_t)(y-k+0.5) ,strokeColor); + + angle = angle + 0.001; + h=(r*cos(angle)); + k=(r*sin(angle)); + + } while (angle<=range); + + +} +// draw a arc outline +void Adafruit_GFX::arc(int16_t x, int16_t y, int16_t r, int16_t st_angle, int16_t end_angle) +{ + + drawArc(x,y,r,st_angle,end_angle,strokeColor); + +} + + #if defined(__SD_H__) // Arduino SD library #define BUFFPIXEL 20 diff --git a/src/utility/Adafruit_GFX.h b/src/utility/Adafruit_GFX.h index ab02b29..c5030fc 100644 --- a/src/utility/Adafruit_GFX.h +++ b/src/utility/Adafruit_GFX.h @@ -60,7 +60,7 @@ #warning "The SD library was not found. loadImage() and image() won't be supported." #endif -inline void swap(int16_t &a, int16_t &b) { int16_t t = a; a = b; b = t; } +#define swap(a, b) { int16_t t = a; a = b; b = t; } /* TODO enum RectMode { @@ -125,7 +125,8 @@ class Adafruit_GFX : public Print { setTextColor(uint16_t c, uint16_t bg), setTextSize(uint8_t s), setTextWrap(boolean w), - setRotation(uint8_t r); + setRotation(uint8_t r), + drawArc(int16_t x, int16_t y, int16_t r, int16_t st_angle, int16_t end_angle,uint16_t color); #if ARDUINO >= 100 virtual size_t write(uint8_t); @@ -185,8 +186,8 @@ class Adafruit_GFX : public Print { quad(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3, int16_t x4, int16_t y4), rect(int16_t x, int16_t y, int16_t width, int16_t height), rect(int16_t x, int16_t y, int16_t width, int16_t height, int16_t radius), - triangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3); - + triangle(int16_t x1, int16_t y1, int16_t x2, int16_t y2, int16_t x3, int16_t y3), + arc(int16_t x, int16_t y, int16_t r, int16_t st_angle, int16_t end_angle); /* TODO void rectMode(RectMode mode); diff --git a/src/utility/Adafruit_ST7735.h b/src/utility/Adafruit_ST7735.h index fbbd6ab..fa3b7c0 100644 --- a/src/utility/Adafruit_ST7735.h +++ b/src/utility/Adafruit_ST7735.h @@ -109,6 +109,7 @@ class Adafruit_ST7735 : public Adafruit_GFX { pushColor(uint16_t color), fillScreen(uint16_t color), drawPixel(int16_t x, int16_t y, uint16_t color), + drawArc(int16_t x, int16_t y, int16_t r, int16_t st_angle, int16_t end_angle,uint16_t color), drawFastVLine(int16_t x, int16_t y, int16_t h, uint16_t color), drawFastHLine(int16_t x, int16_t y, int16_t w, uint16_t color), fillRect(int16_t x, int16_t y, int16_t w, int16_t h, diff --git a/src/utility/keywords.txt b/src/utility/keywords.txt index 9614847..35fa4ad 100644 --- a/src/utility/keywords.txt +++ b/src/utility/keywords.txt @@ -41,6 +41,8 @@ height KEYWORD2 width KEYWORD2 setRotation KEYWORD2 getRotation KEYWORD2 +drawArc KEYWORD2 +arc KEYWORD2 From e470db9e2b0b80812893eb5bbd90f30d05e27bde Mon Sep 17 00:00:00 2001 From: KAbhijeet2105 Date: Thu, 2 Apr 2020 09:23:25 +0530 Subject: [PATCH 3/6] Added new example Rainbow --- examples/Arduino/TFTRainbow/TFTRainbow.ino | 51 ++++++++++++++++++++++ 1 file changed, 51 insertions(+) create mode 100644 examples/Arduino/TFTRainbow/TFTRainbow.ino diff --git a/examples/Arduino/TFTRainbow/TFTRainbow.ino b/examples/Arduino/TFTRainbow/TFTRainbow.ino new file mode 100644 index 0000000..84d9d7e --- /dev/null +++ b/examples/Arduino/TFTRainbow/TFTRainbow.ino @@ -0,0 +1,51 @@ +/* TFTRainbow + by K.Abhijeet + This example code prints the Rainbow to the screen. +*/ + +#include // Arduino LCD library +#include + +// pin definition for the Uno +#define cs 10 +#define dc 9 +#define rst 8 + + +// pin definition for the Leonardo +// #define cs 7 +// #define dc 0 +// #define rst 1 + +// create an instance of the library +TFT TFTscreen = TFT(cs, dc, rst); +int16_t x=80, y=100, r, st_angle=0, end_angle=180; + +void setup() { + + Serial.begin(9600); + + // Put this line at the beginning of every sketch that uses the GLCD: + TFTscreen.begin(); + + // clear the screen with a black background + TFTscreen.background(0, 0, 0); + + // set the font color to white + TFTscreen.stroke(255, 255, 255); + + + TFTscreen.setTextSize(1); + TFTscreen.text("Rainbow: ", 2, 0); + + for(r=0;r<=50;r++) + { + TFTscreen.stroke(random(255),random(255),random(255)); + delay(5); + TFTscreen.arc(x, y, r, st_angle, end_angle); + } + + Serial.println("Rainbow completed!"); +} + +void loop() {} From e2f7e53318354e08242a6f7a568d5fb0bfad9006 Mon Sep 17 00:00:00 2001 From: KAbhijeet2105 Date: Fri, 3 Apr 2020 12:51:38 +0530 Subject: [PATCH 4/6] added new example TFTTriangle --- examples/Arduino/TFTTriangle/TFTTriangle.ino | 79 ++++++++++++++++++++ 1 file changed, 79 insertions(+) create mode 100644 examples/Arduino/TFTTriangle/TFTTriangle.ino diff --git a/examples/Arduino/TFTTriangle/TFTTriangle.ino b/examples/Arduino/TFTTriangle/TFTTriangle.ino new file mode 100644 index 0000000..d9b3456 --- /dev/null +++ b/examples/Arduino/TFTTriangle/TFTTriangle.ino @@ -0,0 +1,79 @@ +/* TFTPointLine + + by K.Abhijeet + This example code takes input x1,y1 x2,y2 and x3,y3 from serial and prints the triangle to the screen + +*/ + +#include // Arduino LCD library +#include + +// pin definition for the Uno +#define cs 10 +#define dc 9 +#define rst 8 + +// pin definition for the Leonardo +// #define cs 7 +// #define dc 0 +// #define rst 1 + +// create an instance of the library +TFT TFTscreen = TFT(cs, dc, rst); +int x1, y1, x2, y2, x3, y3; + +void setup() { + + Serial.begin(9600); + + // Put this line at the beginning of every sketch that uses the GLCD: + TFTscreen.begin(); + + // clear the screen with a black background + TFTscreen.background(0, 0, 0); + + // set the font color to white + TFTscreen.stroke(255, 255, 255); + + // write the static text to the screen + Serial.println("Enter x1 :"); + //waiting for input + while (Serial.available() == 0) {} + x1 = Serial.parseInt(); + + // write the static text to the screen + Serial.println("Enter y1 :"); + //waiting for input + while (Serial.available() == 0) {} + y1 = Serial.parseInt(); + + // write the static text to the screen + Serial.println("Enter x2 :"); + //waiting for input + while (Serial.available() == 0) {} + x2 = Serial.parseInt(); + + // write the static text to the screen + Serial.println("Enter y2 :"); + //waiting for input + while (Serial.available() == 0) {} + y2 = Serial.parseInt(); + + // write the static text to the screen + Serial.println("Enter x3 :"); + //waiting for input + while (Serial.available() == 0) {} + x3 = Serial.parseInt(); + + // write the static text to the screen + Serial.println("Enter y3 :"); + //waiting for input + while (Serial.available() == 0) {} + y3 = Serial.parseInt(); + + //draw triangle to the screen + TFTscreen.triangle(x1, y1, x2, y2, x3, y3); + +} + +void loop() {} From f5d4aada3521a017dcfdc65101e7023994336ce9 Mon Sep 17 00:00:00 2001 From: KAbhijeet2105 Date: Wed, 8 Apr 2020 10:13:42 +0530 Subject: [PATCH 5/6] typo fix --- src/utility/Adafruit_GFX.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/utility/Adafruit_GFX.cpp b/src/utility/Adafruit_GFX.cpp index 9b584ad..b5addf2 100644 --- a/src/utility/Adafruit_GFX.cpp +++ b/src/utility/Adafruit_GFX.cpp @@ -160,7 +160,7 @@ void Adafruit_GFX::fillCircleHelper(int16_t x0, int16_t y0, int16_t r, } } -// Bresenham's algorithm - thx wikpedia +// Bresenham's algorithm - Thanks J.E. Bresenham(1962), Bresenham's line algorithm Wikipedia [URL: https://en.wikipedia.org/wiki/Bresenham%27s_line_algorithm ] void Adafruit_GFX::drawLine(int16_t x0, int16_t y0, int16_t x1, int16_t y1, uint16_t color) From 0195af37a96e1e0573bd2b23f98eeadf8e1a9b58 Mon Sep 17 00:00:00 2001 From: KAbhijeet2105 Date: Mon, 13 Apr 2020 19:26:45 +0530 Subject: [PATCH 6/6] typo fix --- examples/Arduino/TFTArc/TFTArc.ino | 14 ++++++-------- examples/Arduino/TFTCircle/TFTCircle.ino | 9 ++------- examples/Arduino/TFTLine/TFTLine.ino | 15 +++++---------- examples/Arduino/TFTPointLine/TFTPointLine.ino | 13 +++++-------- examples/Arduino/TFTRect/TFTRect.ino | 7 ++----- .../Arduino/TFTStorageRead/TFTStorageRead.ino | 6 ++---- examples/Arduino/TFTTriangle/TFTTriangle.ino | 15 ++++++--------- examples/Arduino/TFTUserText/TFTUserText.ino | 8 +++----- 8 files changed, 31 insertions(+), 56 deletions(-) diff --git a/examples/Arduino/TFTArc/TFTArc.ino b/examples/Arduino/TFTArc/TFTArc.ino index 3e392fb..372a84f 100644 --- a/examples/Arduino/TFTArc/TFTArc.ino +++ b/examples/Arduino/TFTArc/TFTArc.ino @@ -1,6 +1,6 @@ /* TFTArc by K.Abhijeet - This example code takes input x,y(center co-ordinatesof arc ),r(radious),start angle,end angle from serial and prints the arc to the screen. + This example code takes input x, y(center coordinates of arc ), r(radius), start angle and end angle from serial and prints the arc to the screen. */ #include // Arduino LCD library @@ -34,38 +34,36 @@ void setup() { // set the font color to white TFTscreen.stroke(255, 255, 255); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter x :"); //waiting for input while (Serial.available() == 0) {} x = Serial.parseInt(); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter y :"); //waiting for input while (Serial.available() == 0) {} y = Serial.parseInt(); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter r :"); //waiting for input while (Serial.available() == 0) {} r = Serial.parseInt(); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter start angle :"); //waiting for input while (Serial.available() == 0) {} st_angle = Serial.parseInt(); - - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter end angle :"); //waiting for input while (Serial.available() == 0) {} end_angle = Serial.parseInt(); - TFTscreen.setTextSize(1); TFTscreen.text("Your Arc: ", 2, 0); diff --git a/examples/Arduino/TFTCircle/TFTCircle.ino b/examples/Arduino/TFTCircle/TFTCircle.ino index 5629223..db40619 100644 --- a/examples/Arduino/TFTCircle/TFTCircle.ino +++ b/examples/Arduino/TFTCircle/TFTCircle.ino @@ -1,14 +1,12 @@ /* TFTCircle by K.Abhijeet - This example code takes input radius from serial and prints the circle to the screen. */ #include // Arduino LCD library #include - // pin definition for the Uno #define cs 10 #define dc 9 @@ -22,8 +20,6 @@ // create an instance of the library TFT TFTscreen = TFT(cs, dc, rst); - - int red; void setup() { @@ -39,18 +35,17 @@ void setup() { // set the font color to white TFTscreen.stroke(255, 255, 255); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter radius :"); //waiting for input while (Serial.available() == 0) {} red = Serial.parseInt(); - TFTscreen.setTextSize(1); TFTscreen.text("Your circle : ", 2, 0); TFTscreen.fill(255, 255, 0); - TFTscreen.circle( TFTscreen.width()/2, TFTscreen.height()/2, red); // draw circle + TFTscreen.circle( TFTscreen.width() / 2, TFTscreen.height() / 2, red); // draw circle } void loop() {} diff --git a/examples/Arduino/TFTLine/TFTLine.ino b/examples/Arduino/TFTLine/TFTLine.ino index 7d8cb12..788c1a9 100644 --- a/examples/Arduino/TFTLine/TFTLine.ino +++ b/examples/Arduino/TFTLine/TFTLine.ino @@ -1,13 +1,12 @@ /* TFTLine by K.Abhijeet - This example code takes input x1,y1(Initial co-ordinates to draw line) and x2,y2(end co-ordinates to draw line) from serial and prints the line to the screen. + This example code takes input x1,y1(Initial coordinates to draw the line) and x2,y2(end co-ordinates to draw the line) from serial monitor and prints the line to the screen. */ #include // Arduino LCD library #include - // pin definition for the Uno #define cs 10 #define dc 9 @@ -22,7 +21,6 @@ TFT TFTscreen = TFT(cs, dc, rst); int x1, y1, x2, y2; - void setup() { Serial.begin(9600); @@ -36,25 +34,25 @@ void setup() { // set the font color to white TFTscreen.stroke(255, 255, 255); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter x1 :"); //waiting for input while (Serial.available() == 0) {} x1 = Serial.parseInt(); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter y1 :"); //waiting for input while (Serial.available() == 0) {} y1 = Serial.parseInt(); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter x2 :"); //waiting for input while (Serial.available() == 0) {} x2 = Serial.parseInt(); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter y2 :"); //waiting for input while (Serial.available() == 0) {} @@ -62,9 +60,6 @@ void setup() { TFTscreen.setTextSize(1); TFTscreen.text("Your Line : ", 2, 0); - TFTscreen.line(x1, y1, x2, y2); - } - void loop() {} diff --git a/examples/Arduino/TFTPointLine/TFTPointLine.ino b/examples/Arduino/TFTPointLine/TFTPointLine.ino index 2d95dc1..b311ebc 100644 --- a/examples/Arduino/TFTPointLine/TFTPointLine.ino +++ b/examples/Arduino/TFTPointLine/TFTPointLine.ino @@ -1,7 +1,7 @@ /* TFTPointLine by K.Abhijeet - This example code takes input x1,y1(Initial co-ordinates to draw line) and x2,y2(end co-ordinates to draw line) from serial and prints the line to the screen + This example code takes input x1,y1(Initial coordinates to draw the line) and x2,y2(end coordinates to draw the line) from serial monitor and prints the line to the screen by using bresenham’s line drawing algorithm. */ @@ -35,25 +35,25 @@ void setup() { // set the font color to white TFTscreen.stroke(255, 255, 255); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter x1 :"); //waiting for input while (Serial.available() == 0) {} x1 = Serial.parseInt(); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter y1 :"); //waiting for input while (Serial.available() == 0) {} y1 = Serial.parseInt(); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter x2 :"); //waiting for input while (Serial.available() == 0) {} x2 = Serial.parseInt(); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter y2 :"); //waiting for input while (Serial.available() == 0) {} @@ -61,11 +61,8 @@ void setup() { TFTscreen.setTextSize(1); TFTscreen.text("Your Line : ", 2, 0); - drawline(x1, y1, x2, y2); - } - void loop() {} void drawline(int x0, int y0, int x1, int y1) diff --git a/examples/Arduino/TFTRect/TFTRect.ino b/examples/Arduino/TFTRect/TFTRect.ino index c764a27..33ee0a7 100644 --- a/examples/Arduino/TFTRect/TFTRect.ino +++ b/examples/Arduino/TFTRect/TFTRect.ino @@ -1,14 +1,11 @@ /* TFTRect by K.Abhijeet - This example code takes input length and width from serial and prints the rectangle to the screen. */ - #include // Arduino LCD library #include - // pin definition for the Uno #define cs 10 #define dc 9 @@ -39,12 +36,13 @@ void setup() { // set the font color to white TFTscreen.stroke(255, 255, 255); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter length :"); //waiting for input while (Serial.available() == 0) {} len = Serial.parseInt(); + // print text on the serial monitor to instruct user for the input Serial.println("Enter width :"); //waiting for input while (Serial.available() == 0) {} @@ -56,5 +54,4 @@ void setup() { TFTscreen.fill(255, 255, 0); TFTscreen.rect(10, 20, len, wid); // draw rectangle } - void loop() {} diff --git a/examples/Arduino/TFTStorageRead/TFTStorageRead.ino b/examples/Arduino/TFTStorageRead/TFTStorageRead.ino index ee86585..de1bff8 100644 --- a/examples/Arduino/TFTStorageRead/TFTStorageRead.ino +++ b/examples/Arduino/TFTStorageRead/TFTStorageRead.ino @@ -1,10 +1,10 @@ /* TFTStorageRead - This example shows how to read data from an SD card file and prints it to the screen. + This example shows how to read data from an SD card file and prints it to the screen. The circuit: - SD card attached to SPI bus as follows: + SD card attached to SPI bus as follows: ** MOSI - pin 11 ** MISO - pin 12 ** CLK - pin 13 @@ -17,7 +17,6 @@ created by Abhijeet Kadam This example code is in the public domain. - */ // pin definition for the Uno @@ -25,7 +24,6 @@ #define dc 9 #define rst 8 - #include // Arduino LCD library #include #include diff --git a/examples/Arduino/TFTTriangle/TFTTriangle.ino b/examples/Arduino/TFTTriangle/TFTTriangle.ino index d9b3456..621dc15 100644 --- a/examples/Arduino/TFTTriangle/TFTTriangle.ino +++ b/examples/Arduino/TFTTriangle/TFTTriangle.ino @@ -2,7 +2,6 @@ by K.Abhijeet This example code takes input x1,y1 x2,y2 and x3,y3 from serial and prints the triangle to the screen - */ #include // Arduino LCD library @@ -35,37 +34,37 @@ void setup() { // set the font color to white TFTscreen.stroke(255, 255, 255); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter x1 :"); //waiting for input while (Serial.available() == 0) {} x1 = Serial.parseInt(); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter y1 :"); //waiting for input while (Serial.available() == 0) {} y1 = Serial.parseInt(); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter x2 :"); //waiting for input while (Serial.available() == 0) {} x2 = Serial.parseInt(); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter y2 :"); //waiting for input while (Serial.available() == 0) {} y2 = Serial.parseInt(); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter x3 :"); //waiting for input while (Serial.available() == 0) {} x3 = Serial.parseInt(); - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter y3 :"); //waiting for input while (Serial.available() == 0) {} @@ -73,7 +72,5 @@ void setup() { //draw triangle to the screen TFTscreen.triangle(x1, y1, x2, y2, x3, y3); - } - void loop() {} diff --git a/examples/Arduino/TFTUserText/TFTUserText.ino b/examples/Arduino/TFTUserText/TFTUserText.ino index eb5eb89..a45b321 100644 --- a/examples/Arduino/TFTUserText/TFTUserText.ino +++ b/examples/Arduino/TFTUserText/TFTUserText.ino @@ -1,10 +1,8 @@ /* UserText by K.Abhijeet - This example code takes input username from serial and prints to the screen. */ - #include // Arduino LCD library #include @@ -39,7 +37,7 @@ void setup() { TFTscreen.stroke(255, 255, 255); // set the font size - // write the static text to the screen + // print text on the serial monitor to instruct user for the input Serial.println("Enter your name :"); TFTscreen.setTextSize(1); TFTscreen.text("Enter your name :\n ", 2, 2); @@ -47,11 +45,11 @@ void setup() { while (Serial.available() == 0) {} nm = Serial.readString(); // take input from serial nm = "Hello " + nm; + // convert the string to a char array nm.toCharArray(str, 100); + //print the name TFTscreen.text(str, 0, 20); - } - void loop() {}