钻石会员
  
主题
帖子
积分10224
阅读权限50
注册时间2010-11-22
最后登录1970-1-1
在线时间 小时
|
教授在此帖中https://www.yleee.com.cn/thread-41224-1-2.html赠送了一种1.8寸液晶屏,没有人发帖点亮,趁着五一假期,发个帖子。此屏幕和Arduino官方推出的1.8寸屏几乎一样,要说有不一样的地方,一是没带TF卡座,二是印字和官方略有不同。其余都可依照官方示例进行操作。3 H5 z6 ^& L1 Q- s% }+ Z
Arduino Zion板,SPI接口
' d2 r4 `$ U8 ?9 }8 W' N MOSI对应PORTB的26
( V+ j9 @ M2 ]: m7 C MISO对应PORTB的27
' Q* E, @# ]4 z, A8 V SCK 对应PORTB的258 _, S$ S- G0 ?; k# _) @" ]6 J D
这个液晶屏通过SPI接口与ArduinoZion连接,连接方式如下:. j" A5 r4 n$ l5 U
" K5 {3 L# E! g
液晶屏管脚 ArduinoZion d* k( E- @& y* n+ Y7 {2 ?" ?- K
contral-------------3.3v背光控制 可以PWM调光
; m: P1 Z$ W* |4 ?6 ysda----------------(26)MOSI不可更改/ T2 @. z3 n, W+ j7 [3 e2 D3 U
sck----------------(25)SCK不可更改% a( w1 L s5 U+ R5 ?8 {
reset--------------(8)可以更改管脚
9 o3 ]5 s8 z5 m# o% Y% Trs-----------------(9)可以更改管脚# L1 A$ s0 T: q' U7 V- [# g ?$ `
cs-----------------(10)可以更改管脚
" L+ `: s1 t9 B0 x# M4 X连接完毕,然后打开Arduino IDE的文件>示例程序>TFT>Arduino>TFT Display text,你可以看到如下程序:
$ i, W" N% B" B: D: e1 @! Q/*
. G7 R8 A$ A) b' K4 _% I, M5 @% J" W Arduino TFT text example
. @" w) A& E! q7 F* o' I, m 7 s }9 p3 d w$ W1 i P" w
This example demonstrates how to draw text on the
/ o0 ]. p5 J! L1 E TFT with an Arduino. The Arduino reads the value
2 A1 t5 m# m0 y/ F of an analog sensor attached to pin A0, and writes 0 J" `# v1 e3 v1 K' w- W/ P
the value to the LCD screen, updating every8 f; Z) j% z. R) K. j- n3 b
quarter second.
# |- R! @# U( I; d' Q$ R& f- d' D8 [( b . O# J) Q9 D5 m0 D" f) |
This example code is in the public domain# K8 P7 [6 b/ |+ ^; x
Created 15 April 2013 by Scott Fitzgerald
# r: V2 v T6 Q( o , h8 I4 a: T" X
http://arduino.cc/en/Tutorial/TFTDisplayText1 A/ W K% d. Q( T
/ [ x: e# v' ]; K- J */8 O! ^; o" ~- a5 }' O
#include <TFT.h> // Arduino LCD library
6 @3 v7 d; a) [#include <SPI.h>
2 F8 i J/ E2 X+ r) J7 d; I, r- D// pin definition for the Uno
* q( U* b5 a; ?0 z: C8 C4 {" R#define cs 100 E% e' p% j. _* U
#define dc 9; w- h9 ?% i+ k2 v0 e( b3 W. \- ^
#define rst 8 5 W: G, x; |! |$ d
// pin definition for the Leonardo1 D2 v2 @6 ^) `3 R) }7 O
// #define cs 7
/ H& d' |* x" y0 i// #define dc 0; B: w5 o+ K! l& }& w; B n
// #define rst 1
( E7 m6 J# x; u8 u) ^( T// create an instance of the library3 Q% W$ t6 M. {' }4 V
TFT TFTscreen = TFT(cs, dc, rst);
: e8 z0 p' O' N// char array to print to the screen
* o8 k5 B. \0 f% n; x) P# z" ochar sensorPrintout[4];! \# B( \ n( Q. D% m
void setup() {
) V, R# e" D' ]$ F: Z- {0 Q7 J 3 M! ^ ~- U$ ?9 P# |3 c& U
// Put this line at the beginning of every sketch that uses the GLCD:
# c8 B" z; G* ?- D$ K* c; c TFTscreen.begin();# f8 Y2 D9 n, Z$ Y
// clear the screen with a black background
; k9 S/ H/ s( \9 Y( c TFTscreen.background(0, 0, 0);
" _ n7 b% m3 U. o( {9 q
* p7 m9 V6 O* |7 m: v9 B z# r // write the static text to the screen# h6 P9 |! o8 h# r
// set the font color to white
) F5 ]! v9 g8 v/ H& ^ TFTscreen.stroke(255,255,255);
0 ~: h% Z2 q" {8 I // set the font size
" p( e2 T, Y" s& h TFTscreen.setTextSize(2);6 c# \8 f; T4 g1 g. R5 g( z# f
// write the text to the top left corner of the screen: h7 Z8 S* i( N d( V9 l$ o4 N: [
TFTscreen.text("Sensor Value :\n ",0,0);6 d G7 P, V# T( _+ k; R+ l2 |
// ste the font size very large for the loop6 J" ^# D! v7 R: Z
TFTscreen.setTextSize(5);" K8 r) T. a. g
}
+ @( M- U5 }1 ?! F3 ?4 _1 O+ Lvoid loop() {6 G1 @1 Q% U! C8 u, S
// Read the value of the sensor on A0+ F- P; s3 n* }
String sensorVal = String(analogRead(A0));
+ i- N8 K" M. a; H6 P; F ' v2 h- }( {- D& z8 ~* Z& V
// convert the reading to a char array9 K; [( W W; P( w5 ?* l
sensorVal.toCharArray(sensorPrintout, 4);
0 D: b7 n4 Z5 _7 ?6 v // set the font color
7 {2 M. O( o& E' T5 S2 q% i% ~ TFTscreen.stroke(255,255,255);
' t# [( `: k% h3 P // print the sensor value
/ K6 F- n7 N1 d( T5 @ b$ n TFTscreen.text(sensorPrintout, 0, 20);
) y) D1 b4 `% C# v/ H+ O // wait for a moment+ Q( q# E. H/ u% E* e2 q7 Y
delay(250);3 V: \. a0 N+ q! k% |6 m) F
// erase the text you just wrote
/ V9 e1 W, O* p- K3 ` TFTscreen.stroke(0,0,0);/ Q& f% L3 p$ Y% K0 C/ a
TFTscreen.text(sensorPrintout, 0, 20);8 p6 s& D( c* K- e8 v
}1 Q3 ~$ A% w! i7 y: C( X" o, N" p; T
直接下载就可以看到显示的图形,还有几个示例都可以试一下,里边示例有使用TF卡的那就只能外接卡座了,呵呵,可以开心的玩耍了
0 _2 p) ~, y" }4 b+ q4 o( J6 i! A8 U5 r/ w' O" E3 h
5 g5 T; U3 S, V
! M: |! B$ {% r+ Q$ F7 V0 Y7 [* Z- Y/ I
+ A* w$ C X$ u- S; g$ N |
|