-
Notifications
You must be signed in to change notification settings - Fork 43
Added new examples #17
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
Open
KAbhijeet2105
wants to merge
6
commits into
arduino-libraries:master
Choose a base branch
from
KAbhijeet2105:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6614f7e
Added new examples
KAbhijeet2105 afc1704
Enhancement: added a new feature to draw an arc. Added new example TF…
KAbhijeet2105 e470db9
Added new example Rainbow
KAbhijeet2105 e2f7e53
added new example TFTTriangle
KAbhijeet2105 f5d4aad
typo fix
KAbhijeet2105 0195af3
typo fix
KAbhijeet2105 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. | ||
*/ | ||
|
||
#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() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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() {} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.