Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added new examples #17

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
73 changes: 73 additions & 0 deletions examples/Arduino/TFTArc/TFTArc.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
/* TFTArc
by K.Abhijeet
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 <TFT.h> // Arduino LCD library
#include <SPI.h>

// 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);

// 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();

// 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();

// 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();

// 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();

// 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);

TFTscreen.arc(x, y, r, st_angle, end_angle); //draw arc
}

void loop() {}
51 changes: 51 additions & 0 deletions examples/Arduino/TFTCircle/TFTCircle.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* TFTCircle

by K.Abhijeet
This example code takes input radius from serial and prints the circle to the screen.
*/

#include <TFT.h> // Arduino LCD library
#include <SPI.h>

// 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);

// 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
}

void loop() {}
65 changes: 65 additions & 0 deletions examples/Arduino/TFTLine/TFTLine.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/* TFTLine

by K.Abhijeet
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 <TFT.h> // Arduino LCD library
#include <SPI.h>

// 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);

// 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();

// 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();

// 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();

// 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();

TFTscreen.setTextSize(1);
TFTscreen.text("Your Line : ", 2, 0);
TFTscreen.line(x1, y1, x2, y2);
}
void loop() {}
97 changes: 97 additions & 0 deletions examples/Arduino/TFTPointLine/TFTPointLine.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,97 @@
/* TFTPointLine

by K.Abhijeet
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.
*/

#include <TFT.h> // Arduino LCD library
#include <SPI.h>

// 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);

// 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();

// 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();

// 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();

// 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();

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;
}
}
51 changes: 51 additions & 0 deletions examples/Arduino/TFTRainbow/TFTRainbow.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/* TFTRainbow
by K.Abhijeet
This example code prints the Rainbow to the screen.
*/

#include <TFT.h> // Arduino LCD library
#include <SPI.h>

// 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() {}
57 changes: 57 additions & 0 deletions examples/Arduino/TFTRect/TFTRect.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/* TFTRect

by K.Abhijeet
This example code takes input length and width from serial and prints the rectangle to the screen.
*/
#include <TFT.h> // Arduino LCD library
#include <SPI.h>

// 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);

// 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) {}
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() {}
Loading