钻石会员
主题
回帖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卡座,二是印字和官方略有不同。其余都可依照官方示例进行操作。9 z/ E, W9 [- W
Arduino Zion板,SPI接口
5 w. K/ e& e- V! e }; \ MOSI对应PORTB的26
8 T* q' X3 \. U MISO对应PORTB的271 j+ t9 g3 U V- v N& Y
SCK 对应PORTB的25
, G7 j8 h+ k& y/ F% L这个液晶屏通过SPI接口与ArduinoZion连接,连接方式如下:
1 W3 M: t( r4 b. t1 {1 ~4 d/ K* m @6 A0 A; X/ B
液晶屏管脚 ArduinoZion- [8 X2 m' f' Y% L" Q/ b
contral-------------3.3v背光控制 可以PWM调光9 k- i; A" y( W5 `/ B2 X$ B& i
sda----------------(26)MOSI不可更改
/ Z l! O2 T' }. _, J D& u; @sck----------------(25)SCK不可更改
3 m9 |' C% U. sreset--------------(8)可以更改管脚
/ C0 u' [' x+ W$ w. u$ urs-----------------(9)可以更改管脚
6 f4 r7 i* Y* Zcs-----------------(10)可以更改管脚3 y2 P9 T7 \& x3 i o% E* {' H" v$ }; Z
连接完毕,然后打开Arduino IDE的文件>示例程序>TFT>Arduino>TFT Display text,你可以看到如下程序:5 f" O1 m1 `7 ~! B e8 g8 F
/*
& i' k( ]) j# z" h; u+ ?1 ]+ Z Arduino TFT text example; N- |( N, [8 L, J
: p. M) A2 p$ _( |1 z0 D7 v This example demonstrates how to draw text on the
# K! \& X! r" N$ F TFT with an Arduino. The Arduino reads the value
; H# E+ u2 x- u; { of an analog sensor attached to pin A0, and writes
) B1 o. _# {8 U$ v the value to the LCD screen, updating every
3 H. x+ u8 J6 o2 |( F% u. u3 e quarter second.. w8 @( L3 w7 H* I L
( K3 |: @& N2 W1 e. c+ S
This example code is in the public domain
) `; M6 `) S. @ Created 15 April 2013 by Scott Fitzgerald
7 [9 e6 n; ^9 z - U8 C- p+ j0 W6 K( Y& S. W) H
http://arduino.cc/en/Tutorial/TFTDisplayText& u& q( Q0 {4 n9 _# `# Q
# b+ ^0 {& @% L2 H$ g
*/# f8 O; @# c5 `* q
#include <TFT.h> // Arduino LCD library: U- n s& L7 A
#include <SPI.h>
, E: M6 p4 y" Z7 e Z7 A% T// pin definition for the Uno
: t4 n: w% { z. Z2 T8 ^# d1 Q#define cs 10
8 M* p3 i$ j- w/ Z3 _& Q7 Z3 q#define dc 97 S# T+ F; \; e+ u! f
#define rst 8
+ n2 N' q! h/ Q. q// pin definition for the Leonardo% Z8 b& g+ T8 w/ \" c
// #define cs 7
9 W, U" e: c& h! N// #define dc 01 a# ?6 y6 S7 L, f: L6 H0 v+ J7 `
// #define rst 1 . E& s, c+ i; o( J6 u4 s& o5 `
// create an instance of the library3 u. K# a( Q+ ]1 ~/ W) e9 }
TFT TFTscreen = TFT(cs, dc, rst);
$ _2 G) n: k, @& M. j/ d// char array to print to the screen8 Z' ]0 Z) w& z, K5 Z9 L) J
char sensorPrintout[4];6 M$ b% N; |0 O
void setup() {
- N& ]8 ~, d% a4 R9 N' F
0 l/ R6 n4 v7 l9 e4 a% }; u // Put this line at the beginning of every sketch that uses the GLCD:. T# u! k A3 }" C9 M1 v E
TFTscreen.begin();
5 H3 @: V, c5 |) Y! g1 [( z, R4 n // clear the screen with a black background
6 i1 ~- h. ^/ w; X, k S- ] TFTscreen.background(0, 0, 0);
) Z9 i. p [. `6 a
0 Q* K+ w- Q( R: p$ P // write the static text to the screen
& N3 J2 [; _9 M // set the font color to white- _/ E$ V4 f R# W3 D
TFTscreen.stroke(255,255,255);
3 A5 r( K4 K9 w9 p# Y // set the font size
; A% R* H7 C, F1 o0 e) k; u8 M TFTscreen.setTextSize(2);3 D* J2 Y5 y; ^* ~( w. n! d- T! n
// write the text to the top left corner of the screen; M2 s( R! C1 H$ m& r
TFTscreen.text("Sensor Value :\n ",0,0);0 h0 X6 A; M6 P4 R
// ste the font size very large for the loop( X0 Y# D/ n# Y3 Z& l: G5 g0 K
TFTscreen.setTextSize(5);' T4 [ Z2 {& S& I
}
+ j+ `& A2 @; B( x* z3 M7 wvoid loop() {- G7 I& l# q. Q$ e6 M, {0 ]
// Read the value of the sensor on A0
j1 r; b- p1 B) g String sensorVal = String(analogRead(A0));
E# A& e. d* @8 t# J% L
& ^. A( b6 F! f" w // convert the reading to a char array" N% Q* ]/ i* H( n W2 \
sensorVal.toCharArray(sensorPrintout, 4); k. r! E% \$ y& t+ ^
// set the font color
5 `& j, g- J3 S0 K TFTscreen.stroke(255,255,255);8 c3 z& y# |5 ]+ P ^) E
// print the sensor value$ d6 v( v6 R: d. o) Q4 X
TFTscreen.text(sensorPrintout, 0, 20);5 f8 R$ w% F; G4 ?1 Z* ?/ M1 ]6 D
// wait for a moment) D) o; f' E- Y1 e( ^
delay(250);
( ~: T1 N5 D: F9 B% @. B // erase the text you just wrote6 d0 z; _8 I5 R: r! Z# B% P- ]
TFTscreen.stroke(0,0,0);( l1 ?, D d# b# w! J
TFTscreen.text(sensorPrintout, 0, 20);
7 S: z1 s* C6 i6 R. A, a( {}4 K- O. r3 P. A( v
直接下载就可以看到显示的图形,还有几个示例都可以试一下,里边示例有使用TF卡的那就只能外接卡座了,呵呵,可以开心的玩耍了 & n# @. b2 B5 ~% |! t& Z D6 k" E) P
$ o6 n) r: m$ M/ h9 `4 d/ l0 b c
1 X" S, x: p+ y; D
- d8 [: ?. x" y2 g6 [3 C6 h, D* Q
3 W4 B( O( q) B* y |
|