/
rotationtest_highspeed.pde
278 lines (217 loc) · 7.52 KB
/
rotationtest_highspeed.pde
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
/***************************************************
This is an example sketch for the Adafruit 1.8" SPI display.
This library works with the Adafruit 1.8" TFT Breakout w/SD card
----> http://www.adafruit.com/products/358
as well as Adafruit raw 1.8" TFT display
----> http://www.adafruit.com/products/618
Check out the links above for our tutorials and wiring diagrams
These displays use SPI to communicate, 4 or 5 pins are required to
interface (RST is optional)
Adafruit invests time and resources providing this open source code,
please support Adafruit and open-source hardware by purchasing
products from Adafruit!
Written by Limor Fried/Ladyada for Adafruit Industries.
MIT license, all text above must be included in any redistribution
****************************************************/
//#define sclk 13
//#define mosi 11
#define cs 10
#define dc 9
#define rst 8 // you can also connect this to the Arduino reset
#include <Adafruit_GFX.h> // Core graphics library
#include <Adafruit_ST7735.h> // Hardware-specific library
#include <SPI.h>
// Option 1: use any pins but a little slower
//Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, mosi, sclk, rst);
// Option 2: must use the hardware SPI pins
// (for UNO thats sclk = 13 and sid = 11) and pin 10 must be
// an output. This is much faster - also required if you want
// to use the microSD card (see the image drawing example)
Adafruit_ST7735 tft = Adafruit_ST7735(cs, dc, rst);
void setup(void) {
Serial.begin(9600);
Serial.print("hello!");
// Our supplier changed the 1.8" display slightly after Jan 10, 2012
// so that the alignment of the TFT had to be shifted by a few pixels
// this just means the init code is slightly different. Check the
// color of the tab to see which init code to try. If the display is
// cut off or has extra 'random' pixels on the top & left, try the
// other option!
// If your TFT's plastic wrap has a Red Tab, use the following:
tft.initR(INITR_REDTAB); // initialize a ST7735R chip, red tab
// If your TFT's plastic wrap has a Green Tab, use the following:
//tft.initR(INITR_GREENTAB); // initialize a ST7735R chip, green tab
Serial.println("init");
tft.fillScreen(ST7735_BLACK);
Serial.println("This is a test of the rotation capabilities of the TFT library!");
Serial.println("Press <SEND> (or type a character) to advance");
}
void loop(void) {
rotateLine();
rotateText();
rotatePixel();
rotateFastline();
rotateDrawrect();
rotateFillrect();
rotateDrawcircle();
rotateFillcircle();
rotateTriangle();
rotateFillTriangle();
rotateRoundRect();
rotateFillRoundRect();
rotateChar();
rotateString();
}
void rotateText() {
for (uint8_t i=0; i<4; i++) {
tft.fillScreen(ST7735_BLACK);
Serial.println(tft.getRotation(), DEC);
tft.setCursor(0, 30);
tft.setTextColor(ST7735_RED);
tft.setTextSize(1);
tft.println("Hello World!");
tft.setTextColor(ST7735_YELLOW);
tft.setTextSize(2);
tft.println("Hello World!");
tft.setTextColor(ST7735_GREEN);
tft.setTextSize(3);
tft.println("Hello World!");
tft.setTextColor(ST7735_BLUE);
tft.setTextSize(4);
tft.print(1234.567);
while (!Serial.available());
Serial.read(); Serial.read(); Serial.read();
tft.setRotation(tft.getRotation()+1);
}
}
void rotateFillcircle(void) {
for (uint8_t i=0; i<4; i++) {
tft.fillScreen(ST7735_BLACK);
Serial.println(tft.getRotation(), DEC);
tft.fillCircle(10, 30, 10, ST7735_YELLOW);
while (!Serial.available());
Serial.read(); Serial.read(); Serial.read();
tft.setRotation(tft.getRotation()+1);
}
}
void rotateDrawcircle(void) {
for (uint8_t i=0; i<4; i++) {
tft.fillScreen(ST7735_BLACK);
Serial.println(tft.getRotation(), DEC);
tft.drawCircle(10, 30, 10, ST7735_YELLOW);
while (!Serial.available());
Serial.read(); Serial.read(); Serial.read();
tft.setRotation(tft.getRotation()+1);
}
}
void rotateFillrect(void) {
for (uint8_t i=0; i<4; i++) {
tft.fillScreen(ST7735_BLACK);
Serial.println(tft.getRotation(), DEC);
tft.fillRect(10, 20, 10, 20, ST7735_GREEN);
while (!Serial.available());
Serial.read(); Serial.read(); Serial.read();
tft.setRotation(tft.getRotation()+1);
}
}
void rotateDrawrect(void) {
for (uint8_t i=0; i<4; i++) {
tft.fillScreen(ST7735_BLACK);
Serial.println(tft.getRotation(), DEC);
tft.drawRect(10, 20, 10, 20, ST7735_GREEN);
while (!Serial.available());
Serial.read(); Serial.read(); Serial.read();
tft.setRotation(tft.getRotation()+1);
}
}
void rotateFastline(void) {
for (uint8_t i=0; i<4; i++) {
tft.fillScreen(ST7735_BLACK);
Serial.println(tft.getRotation(), DEC);
tft.drawHorizontalLine(0, 20, tft.width(), ST7735_RED);
tft.drawVerticalLine(20, 0, tft.height(), ST7735_BLUE);
while (!Serial.available());
Serial.read(); Serial.read(); Serial.read();
tft.setRotation(tft.getRotation()+1);
}
}
void rotateLine(void) {
for (uint8_t i=0; i<4; i++) {
tft.fillScreen(ST7735_BLACK);
Serial.println(tft.getRotation(), DEC);
tft.drawLine(tft.width()/2, tft.height()/2, 0, 0, ST7735_RED);
while (!Serial.available());
Serial.read(); Serial.read(); Serial.read();
tft.setRotation(tft.getRotation()+1);
}
}
void rotatePixel(void) {
for (uint8_t i=0; i<4; i++) {
tft.fillScreen(ST7735_BLACK);
Serial.println(tft.getRotation(), DEC);
tft.drawPixel(10,20, ST7735_WHITE);
while (!Serial.available());
Serial.read(); Serial.read(); Serial.read();
tft.setRotation(tft.getRotation()+1);
}
}
void rotateTriangle(void) {
for (uint8_t i=0; i<4; i++) {
tft.fillScreen(ST7735_BLACK);
Serial.println(tft.getRotation(), DEC);
tft.drawTriangle(20, 10, 10, 30, 30, 30, ST7735_GREEN);
while (!Serial.available());
Serial.read(); Serial.read(); Serial.read();
tft.setRotation(tft.getRotation()+1);
}
}
void rotateFillTriangle(void) {
for (uint8_t i=0; i<4; i++) {
tft.fillScreen(ST7735_BLACK);
Serial.println(tft.getRotation(), DEC);
tft.fillTriangle(20, 10, 10, 30, 30, 30, ST7735_RED);
while (!Serial.available());
Serial.read(); Serial.read(); Serial.read();
tft.setRotation(tft.getRotation()+1);
}
}
void rotateRoundRect(void) {
for (uint8_t i=0; i<4; i++) {
tft.fillScreen(ST7735_BLACK);
Serial.println(tft.getRotation(), DEC);
tft.drawRoundRect(20, 10, 25, 15, 5, ST7735_BLUE);
while (!Serial.available());
Serial.read(); Serial.read(); Serial.read();
tft.setRotation(tft.getRotation()+1);
}
}
void rotateFillRoundRect(void) {
for (uint8_t i=0; i<4; i++) {
tft.fillScreen(ST7735_BLACK);
Serial.println(tft.getRotation(), DEC);
tft.fillRoundRect(20, 10, 25, 15, 5, ST7735_CYAN);
while (!Serial.available());
Serial.read(); Serial.read(); Serial.read();
tft.setRotation(tft.getRotation()+1);
}
}
void rotateChar(void) {
for (uint8_t i=0; i<4; i++) {
tft.fillScreen(ST7735_BLACK);
Serial.println(tft.getRotation(), DEC);
tft.drawChar(25, 15, 'A', ST7735_WHITE, ST7735_WHITE, 1);
while (!Serial.available());
Serial.read(); Serial.read(); Serial.read();
tft.setRotation(tft.getRotation()+1);
}
}
void rotateString(void) {
for (uint8_t i=0; i<4; i++) {
tft.fillScreen(ST7735_BLACK);
Serial.println(tft.getRotation(), DEC);
tft.drawString(8, 25, "Adafruit Industries", ST7735_WHITE);
while (!Serial.available());
Serial.read(); Serial.read(); Serial.read();
tft.setRotation(tft.getRotation()+1);
}
}