钻石会员
主题
回帖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卡座,二是印字和官方略有不同。其余都可依照官方示例进行操作。+ m* X6 c* p2 j" H% l8 t- A. U, A X
Arduino Zion板,SPI接口 ; ?2 R/ [1 l9 c i
MOSI对应PORTB的26
# c7 Q: L( l' @# B. b' Z$ z# E5 V+ X MISO对应PORTB的27
( U, b) }. K0 [ SCK 对应PORTB的250 D; H4 i) Z5 k, c
这个液晶屏通过SPI接口与ArduinoZion连接,连接方式如下:2 T2 i% H! X$ N7 Q+ @! x2 y9 x
5 l6 ?5 t# U: n* m# U7 Q8 V: X液晶屏管脚 ArduinoZion/ M) b) Q4 |9 e$ \: l! A* M \! l
contral-------------3.3v背光控制 可以PWM调光
: x& C+ ?/ }/ lsda----------------(26)MOSI不可更改5 o" Y# U9 J' Y" ?
sck----------------(25)SCK不可更改" _( M" E9 d6 Z2 _. c
reset--------------(8)可以更改管脚! J: |8 k8 ~) R! u/ j. Q
rs-----------------(9)可以更改管脚8 g+ z( Y) P! U, P5 T j
cs-----------------(10)可以更改管脚: O" d) E, j4 g
连接完毕,然后打开Arduino IDE的文件>示例程序>TFT>Arduino>TFT Display text,你可以看到如下程序:
2 a: X6 `/ o( |- r: A/*( z7 _: i* H/ {$ X% p5 W- ^6 @
Arduino TFT text example
6 s1 s' i) K, j8 z! X# P
( S6 R, v& ]# i8 Q This example demonstrates how to draw text on the
/ w+ k+ M; Z/ ~6 ~ TFT with an Arduino. The Arduino reads the value
. D1 `2 j: w" l/ V) f! E of an analog sensor attached to pin A0, and writes # k$ F: m) G2 U/ Q3 x {
the value to the LCD screen, updating every
3 o8 V0 A4 c7 i* `7 L quarter second.
+ A' q! p1 k* R/ @( A 2 L7 k' B1 ? l$ C
This example code is in the public domain7 ^' \4 l9 a# r2 M) o
Created 15 April 2013 by Scott Fitzgerald7 y4 h p$ @4 |% E
2 ]* P' Q3 w1 [+ E" g# y http://arduino.cc/en/Tutorial/TFTDisplayText* Z' w6 a4 _: k, v! J0 _! ^
/ m$ M$ k4 w% I c7 _- ~ */
) D. L1 E& e( W) T* ?3 l7 h! j1 @" M#include <TFT.h> // Arduino LCD library
% z# ~0 S6 |; H1 V#include <SPI.h>
7 r8 v$ o% P/ _3 m// pin definition for the Uno& \0 Q' V$ R2 B* {
#define cs 104 q" Z( x+ {5 G/ B6 |" C
#define dc 9
5 J$ o1 N x L; b: g#define rst 8 ; z- R5 ]! Q/ e, Z) p3 k! [% y# x D
// pin definition for the Leonardo
7 ~7 f* a# _: k' g// #define cs 7% H' }4 Q5 l8 R+ m
// #define dc 0
2 ?% @/ X/ d5 k. Y5 i9 I7 {# ^8 r// #define rst 1
4 j$ c) _6 c- c6 A// create an instance of the library% g0 V! _* P0 P. W
TFT TFTscreen = TFT(cs, dc, rst);
1 o8 c7 D3 J/ N+ V m7 y4 R, U0 B// char array to print to the screen/ h% i2 _4 m' G8 h7 ]/ k
char sensorPrintout[4];
% k4 k* }3 X3 l3 k5 I0 r' ^void setup() {& a& h) Z# D! s$ M% r1 A
1 h% o0 m" W0 e0 q
// Put this line at the beginning of every sketch that uses the GLCD:
( q0 F+ B6 |+ A5 P6 ]8 y" a5 r2 b TFTscreen.begin();' l) Q0 I& |3 j. N
// clear the screen with a black background u& y B! O4 u2 ?& p# Z
TFTscreen.background(0, 0, 0);0 r. T8 y/ f, X( y. _% {6 {- x
& |, J6 o! S% _ ~; F: o/ t/ L // write the static text to the screen
0 J- k) k1 f" f5 y& t // set the font color to white
5 s* X. c$ V0 K& N. s3 X TFTscreen.stroke(255,255,255);3 s, a3 W3 w! Q. @3 B) ~
// set the font size
4 U# Y8 S4 Y* C4 p% W2 a8 ~6 [( |# l! B TFTscreen.setTextSize(2);5 F: j% Z1 G: D7 c
// write the text to the top left corner of the screen5 a: q4 T: V- u7 z2 ]6 g
TFTscreen.text("Sensor Value :\n ",0,0);
6 h" |- o; j7 S8 ?! e E+ `" x0 g4 d // ste the font size very large for the loop
0 B, a7 v+ ?; s% B2 M3 r P TFTscreen.setTextSize(5);$ e! X* e, m5 m+ i& \/ E
}; L4 m# W% L5 B$ c7 R$ c4 G6 X5 {
void loop() {
! J7 }) y. \- I5 {4 @6 F // Read the value of the sensor on A0
. n3 O+ U7 C7 o0 ~, m8 ~ String sensorVal = String(analogRead(A0));
4 S9 R- c8 t8 B5 c/ c 9 I; }# \ A/ x( G) w0 x- N
// convert the reading to a char array/ V/ ~& |6 \" Z4 t8 W$ P6 @
sensorVal.toCharArray(sensorPrintout, 4);
1 a% T+ ?# x) Q/ a3 l5 S // set the font color( {5 }8 L. b s% d* J% Y
TFTscreen.stroke(255,255,255);
, v* ^" ` K* w9 e // print the sensor value% ^0 @$ s$ _2 t& n# R
TFTscreen.text(sensorPrintout, 0, 20);
. Q J" w( O4 e" w S // wait for a moment" j2 F" y, l0 m, U3 ?
delay(250);
3 s' }- e5 `" [; J, n* f8 b // erase the text you just wrote1 m! `% @( f* u) c# p
TFTscreen.stroke(0,0,0);+ X7 H E9 S9 i$ Z2 J) C
TFTscreen.text(sensorPrintout, 0, 20);5 K% Z5 ~) y. J( d
}$ `. w; |3 E5 z2 K( J
直接下载就可以看到显示的图形,还有几个示例都可以试一下,里边示例有使用TF卡的那就只能外接卡座了,呵呵,可以开心的玩耍了 5 e6 f0 L6 _2 b1 x9 i F8 }
4 Z* _! P5 R# m9 A& c4 w3 X X9 e1 b/ n4 ^9 y
1 k% J* I% M/ n( @) c
: v3 A. I% u3 j$ d+ m9 [! B) D. g5 Y! p; }5 V5 ? e* Z
|
|