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 4 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
75 changes: 75 additions & 0 deletions examples/Arduino/TFTArc/TFTArc.ino
Original file line number Diff line number Diff line change
@@ -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.
KAbhijeet2105 marked this conversation as resolved.
Show resolved Hide resolved
*/

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

// write the static text to the screen
KAbhijeet2105 marked this conversation as resolved.
Show resolved Hide resolved
Serial.println("Enter x :");
//waiting for input
while (Serial.available() == 0) {}
x = Serial.parseInt();

// write the static text to the screen
KAbhijeet2105 marked this conversation as resolved.
Show resolved Hide resolved
Serial.println("Enter y :");
//waiting for input
while (Serial.available() == 0) {}
y = Serial.parseInt();

// write the static text to the screen
KAbhijeet2105 marked this conversation as resolved.
Show resolved Hide resolved
Serial.println("Enter r :");
//waiting for input
while (Serial.available() == 0) {}
r = Serial.parseInt();

// write the static text to the screen
KAbhijeet2105 marked this conversation as resolved.
Show resolved Hide resolved
Serial.println("Enter start angle :");
//waiting for input
while (Serial.available() == 0) {}
st_angle = Serial.parseInt();


// write the static text to the screen
KAbhijeet2105 marked this conversation as resolved.
Show resolved Hide resolved
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() {}
56 changes: 56 additions & 0 deletions examples/Arduino/TFTCircle/TFTCircle.ino
Original file line number Diff line number Diff line change
@@ -0,0 +1,56 @@
/* 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);

// write the static text to the screen
KAbhijeet2105 marked this conversation as resolved.
Show resolved Hide resolved
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() {}
70 changes: 70 additions & 0 deletions examples/Arduino/TFTLine/TFTLine.ino
Original file line number Diff line number Diff line change
@@ -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.
KAbhijeet2105 marked this conversation as resolved.
Show resolved Hide resolved
*/

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

// write the static text to the screen
KAbhijeet2105 marked this conversation as resolved.
Show resolved Hide resolved
Serial.println("Enter x1 :");
//waiting for input
while (Serial.available() == 0) {}
x1 = Serial.parseInt();

// write the static text to the screen
KAbhijeet2105 marked this conversation as resolved.
Show resolved Hide resolved
Serial.println("Enter y1 :");
//waiting for input
while (Serial.available() == 0) {}
y1 = Serial.parseInt();

// write the static text to the screen
KAbhijeet2105 marked this conversation as resolved.
Show resolved Hide resolved
Serial.println("Enter x2 :");
//waiting for input
while (Serial.available() == 0) {}
x2 = Serial.parseInt();

// write the static text to the screen
KAbhijeet2105 marked this conversation as resolved.
Show resolved Hide resolved
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() {}
100 changes: 100 additions & 0 deletions examples/Arduino/TFTPointLine/TFTPointLine.ino
Original file line number Diff line number Diff line change
@@ -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
KAbhijeet2105 marked this conversation as resolved.
Show resolved Hide resolved
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);

// 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
KAbhijeet2105 marked this conversation as resolved.
Show resolved Hide resolved
Serial.println("Enter y1 :");
//waiting for input
while (Serial.available() == 0) {}
y1 = Serial.parseInt();

// write the static text to the screen
KAbhijeet2105 marked this conversation as resolved.
Show resolved Hide resolved
Serial.println("Enter x2 :");
//waiting for input
while (Serial.available() == 0) {}
x2 = Serial.parseInt();

// write the static text to the screen
KAbhijeet2105 marked this conversation as resolved.
Show resolved Hide resolved
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() {}
Loading