钻石会员
主题
回帖0
积分10224
阅读权限50
注册时间2010-11-22
最后登录1970-1-1
在线时间 小时
|
教授在此帖中https://www.yleee.com.cn/thread-41224-1-2.html赠送了一种1.8寸液晶屏,没有人发帖点亮,趁着五一假期,发个帖子。此屏幕和Arduino官方推出的1.8寸屏几乎一样,要说有不一样的地方,一是没带TF卡座,二是印字和官方略有不同。其余都可依照官方示例进行操作。6 _* t3 T+ D7 e2 Y4 M% c
Arduino Zion板,SPI接口
# H5 P. ^2 \4 f, U MOSI对应PORTB的26
8 d/ M& i# A; p5 B: e MISO对应PORTB的27# k( ]' `& Q6 E$ R! k0 x& l& d
SCK 对应PORTB的25
, i% Z- ~' |6 p! j6 U这个液晶屏通过SPI接口与ArduinoZion连接,连接方式如下:! O8 v1 [0 ^0 v4 S/ x, J
% [ w7 g% E% L4 l
液晶屏管脚 ArduinoZion
) U, [" A# c5 @) y/ q: m' mcontral-------------3.3v背光控制 可以PWM调光) ?5 u( }7 r8 N: `4 `! @
sda----------------(26)MOSI不可更改* G5 q/ o4 P: Y/ v, Y o
sck----------------(25)SCK不可更改
. G* \' L1 c5 {8 G5 y$ yreset--------------(8)可以更改管脚& R9 W N, L( N" Z8 ]! W4 g5 |
rs-----------------(9)可以更改管脚$ Q m4 w- M9 x* M a) j* \& T( S) q; _
cs-----------------(10)可以更改管脚5 e. g- d$ Y' c# ~/ t
连接完毕,然后打开Arduino IDE的文件>示例程序>TFT>Arduino>TFT Display text,你可以看到如下程序:
& x$ N3 k2 O9 K+ f; O6 O* N( b/*7 h" M0 g) v+ C) e3 _% X A/ J& a1 T
Arduino TFT text example
/ Q7 I0 j8 j9 m8 B4 W* b % g! Z6 X" T7 F) W0 @" v& R+ k) P1 g
This example demonstrates how to draw text on the . o& N% \+ s% z
TFT with an Arduino. The Arduino reads the value
+ C. `# i$ ~6 Z of an analog sensor attached to pin A0, and writes
. G2 W- T* h3 B v( j the value to the LCD screen, updating every
/ |8 W+ Y8 O6 S' e0 V' U3 e% Q* ` quarter second.1 N# O' z7 W8 p& t& J
& q4 V7 U) Y" `: |
This example code is in the public domain
5 Q! P8 G, v' V( E Created 15 April 2013 by Scott Fitzgerald
1 V' x% y0 ~7 }7 y0 a; r6 Y
& j9 h$ a3 Q6 N' d0 G; d http://arduino.cc/en/Tutorial/TFTDisplayText( E2 m u8 j5 Y2 P: m1 w
6 \( [' \+ ~- c3 j Y
*/& a8 x3 M" ^' |9 P
#include <TFT.h> // Arduino LCD library; U" v: l5 @! U4 y6 W: m/ A
#include <SPI.h>
. [ H, L# ^7 Y% f! `( T0 u( w// pin definition for the Uno6 Q; {7 g( j& p+ M% C
#define cs 10 n/ r% x+ b9 P: W# n/ x2 G# V/ F1 i/ X
#define dc 9
9 l( }# n6 M- Z7 p#define rst 8 9 y! v/ K+ H) m) b1 T' Z1 H; w o: o
// pin definition for the Leonardo
1 x- E. J- W5 G% i" F# ~// #define cs 76 Y/ m5 `: H' {) M8 }
// #define dc 04 }0 `9 L0 X8 t# D/ f5 R+ v
// #define rst 1 5 B, c2 O% [6 |) h2 i4 Q
// create an instance of the library: E$ J$ ?$ T0 m
TFT TFTscreen = TFT(cs, dc, rst);
) J$ f" n3 J% I5 w// char array to print to the screen/ _: M, S h" L: Q6 c# O' {: W4 W
char sensorPrintout[4];' M' O# o4 {8 H% G
void setup() {; g9 \* u' D6 x' Y6 ^, p
. [* K+ [ U" w# z3 | // Put this line at the beginning of every sketch that uses the GLCD:
0 \ p, Y/ F/ n( z TFTscreen.begin();
2 X' Z, V v3 c; X, u, w# _0 s // clear the screen with a black background
8 F; m3 v2 @( e, g- { TFTscreen.background(0, 0, 0);
; c; b' ~4 B6 C/ t
+ w' Y, u, R* M% t* K9 Z7 G // write the static text to the screen
1 L$ Q z) L8 w3 y3 D // set the font color to white
! \/ m3 H1 \8 H& H& F: E TFTscreen.stroke(255,255,255);
. r& |8 G6 o( F8 l) L9 _2 ]5 z // set the font size3 z2 ^! p1 Y+ q7 a5 M/ F E4 n8 O/ O
TFTscreen.setTextSize(2);8 ]3 b5 l2 b! u3 h$ J+ `. J
// write the text to the top left corner of the screen: f7 b1 L% q+ l
TFTscreen.text("Sensor Value :\n ",0,0);" z2 ]( @6 H/ i2 P! h! K
// ste the font size very large for the loop
$ w1 L, i5 e. P2 j# C: N @ TFTscreen.setTextSize(5);, g I6 Y2 s/ ~4 a- h1 {
}0 v# ?! E/ q8 P/ e/ N
void loop() {
8 s/ K3 _# i9 l' s3 j // Read the value of the sensor on A00 v. _3 r/ Z" k8 }. q
String sensorVal = String(analogRead(A0));
: T& ]: X/ z' E+ Z7 h% b % v- @4 p# @1 f& }7 e
// convert the reading to a char array. |$ ?% m1 n1 K* x4 t! e3 }
sensorVal.toCharArray(sensorPrintout, 4);1 E H9 R C, Y0 M
// set the font color# H% w( ~& h( ~* w) J6 R6 s
TFTscreen.stroke(255,255,255);: R: s+ `" a& t/ q1 A; K
// print the sensor value9 A1 a2 i4 v' j4 Z% {2 b. L1 e" X
TFTscreen.text(sensorPrintout, 0, 20);$ C% @2 t' Q+ n+ d- G9 T$ Q
// wait for a moment3 O1 R5 Q9 @3 b. y7 L' W- n$ T
delay(250);/ X7 C0 x U1 Q$ {- ~
// erase the text you just wrote* i+ N0 p1 t+ W k* M, i
TFTscreen.stroke(0,0,0);
* T$ r2 O7 P6 Y TFTscreen.text(sensorPrintout, 0, 20);; V7 [4 t+ h$ r5 X
}( \. Q3 l+ F/ G; t
直接下载就可以看到显示的图形,还有几个示例都可以试一下,里边示例有使用TF卡的那就只能外接卡座了,呵呵,可以开心的玩耍了 9 I3 {. U9 q8 L
+ Y0 a- R, B+ H3 z8 j
4 D( _9 q+ M) v$ \, E. M2 a1 I' R8 @0 y) ~! u4 e9 \5 m, ?
; a- ~: J) B0 t- z( f8 a
" H* ?' M' ~# n, e |
|