钻石会员
主题
回帖0
积分10225
阅读权限50
注册时间2010-11-22
最后登录1970-1-1
在线时间 小时
|
教授在此帖中https://www.yleee.com.cn/thread-41224-1-2.html赠送了一种1.8寸液晶屏,没有人发帖点亮,趁着五一假期,发个帖子。此屏幕和Arduino官方推出的1.8寸屏几乎一样,要说有不一样的地方,一是没带TF卡座,二是印字和官方略有不同。其余都可依照官方示例进行操作。
) l1 s0 U' d8 o# C! X- t7 @Arduino Zion板,SPI接口 6 i$ i" G. ]% F4 r J
MOSI对应PORTB的26
1 K4 f4 n8 K1 @; w6 m MISO对应PORTB的27
2 P3 [7 \/ s1 [ SCK 对应PORTB的25: d. I: I% x& B6 a3 W
这个液晶屏通过SPI接口与ArduinoZion连接,连接方式如下:
0 |, k" k4 T% ^: s$ l. K4 w/ L
4 d$ r' y u7 Q液晶屏管脚 ArduinoZion' N; w' Y: R, x. z% t5 t) ~
contral-------------3.3v背光控制 可以PWM调光. W7 l" s$ P0 R) F$ F
sda----------------(26)MOSI不可更改
/ C) T3 j3 b& @ z) X- Z: Y" isck----------------(25)SCK不可更改
2 L) [# O, w6 J4 O) ireset--------------(8)可以更改管脚
7 h: a; S- T' }8 k& Frs-----------------(9)可以更改管脚: z1 j2 j: L" |* Z2 v
cs-----------------(10)可以更改管脚+ ^' B* D8 ^' c! m6 M
连接完毕,然后打开Arduino IDE的文件>示例程序>TFT>Arduino>TFT Display text,你可以看到如下程序:
$ A- q" C1 S5 `/*& e b8 I: `4 L9 E: u/ V
Arduino TFT text example
5 X: r m" v; m2 V P 4 P$ X5 s& a4 P" T$ A" G- X; ?0 O
This example demonstrates how to draw text on the - C9 G8 C8 I/ i# u
TFT with an Arduino. The Arduino reads the value
$ _6 S# l2 v/ j( t* G2 x of an analog sensor attached to pin A0, and writes ! {8 P B( h% B; `5 v. B( N% v6 T
the value to the LCD screen, updating every
+ e: w0 b7 @ C% \2 D* C" @6 p% t quarter second.
; V1 L( K& v8 F
. C; o4 W, ^3 ]0 D1 o) y/ } This example code is in the public domain
+ [# p1 ]" a/ i: h4 O% m- m- H! P Created 15 April 2013 by Scott Fitzgerald/ d! f; v; M( o. w& }$ F% A
( T, Q2 e/ a3 ^- |4 J5 k! C# N
http://arduino.cc/en/Tutorial/TFTDisplayText$ H- d$ l7 J3 \/ E" \3 B
% G( i6 t+ h0 T) j& b/ e4 e
*/
" z, u) c: L! J8 E& T#include <TFT.h> // Arduino LCD library
* Y5 w1 Q! ]7 L" v. O4 \& {#include <SPI.h>
6 \* n- |8 i7 t# U// pin definition for the Uno! d7 u- x+ \: I5 s1 x# \3 W* ]$ r
#define cs 10( |8 J6 X5 G% Y1 c; {4 U
#define dc 9: w* t" i9 L8 D$ M1 O
#define rst 8 ' a- q2 ^0 f1 E5 q
// pin definition for the Leonardo
% ~" @1 f! y) l" O0 r& \6 H0 o// #define cs 7
0 g3 H p! G$ O# e" H/ n// #define dc 0
* C& a' Z6 ~0 J' S5 p. Y% J3 \// #define rst 1 ( c) d, O. ^3 V4 o! C
// create an instance of the library
, b6 N; P3 K& [; M h: q- k+ @+ @TFT TFTscreen = TFT(cs, dc, rst);
2 q$ J3 I3 ^) ^1 N2 h! ?) K- Z// char array to print to the screen# T! Q$ V" e3 t
char sensorPrintout[4];$ X2 l# J" [6 x5 @( P" v
void setup() {1 d& O u0 y; b" O$ ]5 ^$ p- [' [
, g& i' B+ T8 Z. H" E" A
// Put this line at the beginning of every sketch that uses the GLCD:0 P1 O Q4 ~3 X& u! f) U
TFTscreen.begin();
( G; E7 z' c- l; N // clear the screen with a black background
" z% ~# Y8 l0 D+ J' u B* B7 `7 d TFTscreen.background(0, 0, 0);/ S, {* u9 V4 F
* i8 Y% l+ V/ {/ b% c, |
// write the static text to the screen6 q X" P5 o& N1 d) v0 h* J
// set the font color to white, E" E0 s" z; M& }
TFTscreen.stroke(255,255,255);
7 H3 F6 f8 C% l% `2 r // set the font size( }5 W8 V1 J) k
TFTscreen.setTextSize(2);! V0 V2 h/ w% e9 r1 ?
// write the text to the top left corner of the screen! s8 ?( ]' N {6 n6 s- b: d: I
TFTscreen.text("Sensor Value :\n ",0,0);
7 ]+ z: q5 c$ m7 q1 } // ste the font size very large for the loop
2 `( Q+ K1 E7 h# m o- U+ k TFTscreen.setTextSize(5);
% l1 O4 X% G+ g4 S8 L" o}% w# n. w/ S0 W4 q! }4 Q. |
void loop() {+ W. J% W# H5 N; q
// Read the value of the sensor on A0
9 D8 i. U9 Z6 L: J. K5 B String sensorVal = String(analogRead(A0));1 e! U& a u+ B |( a& ^" J
; j, ~; h' o- a. K$ e' e$ S# p
// convert the reading to a char array
k, @: x6 W( t" s sensorVal.toCharArray(sensorPrintout, 4);9 h! H* O! @2 q( f; ^2 a# o9 a
// set the font color
; }: F* h7 i+ }+ ?7 V TFTscreen.stroke(255,255,255);
& p3 r0 P" A& W# V7 g- {3 d // print the sensor value- k( W9 X6 X4 ^2 w4 x# ~/ e8 h4 q
TFTscreen.text(sensorPrintout, 0, 20);" b- z& R$ [, P: z3 G1 b
// wait for a moment
3 o0 t' d3 V7 J* I. }! K delay(250);3 K" p& Q3 v G1 }& E* o) m5 `
// erase the text you just wrote
% b3 s! j- k! B n# | TFTscreen.stroke(0,0,0);
9 i" X8 q1 S4 e6 H6 q TFTscreen.text(sensorPrintout, 0, 20);$ {" S" b! e0 x3 ]1 D9 ?5 w
}! d% `5 Y1 \; U
直接下载就可以看到显示的图形,还有几个示例都可以试一下,里边示例有使用TF卡的那就只能外接卡座了,呵呵,可以开心的玩耍了
+ r7 O+ o: C" M
" z+ g5 J5 s, w E9 K+ x0 p: s, f) e# W1 q
2 r1 g* z p- z( c# Q ?$ O$ B
; K$ x7 t, g2 n: W. W. }8 n0 h
2 q) Q% X# Y5 ~5 ?# a, v/ ]& K' r; u6 E |
|