一乐电子

 找回密码
 请使用微信账号登录和注册会员

QQ登录

只需一步,快速开始

微信扫码登录

手机号码,快捷登录

手机号码,快捷登录

搜索
查看: 4662|回复: 2

使用Arduino Zion驱动教授赠送的1.8寸液晶屏

[复制链接]
发表于 2015-5-1 22:57 | 显示全部楼层 |阅读模式
教授在此帖中https://www.yleee.com.cn/thread-41224-1-2.html赠送了一种1.8寸液晶屏,没有人发帖点亮,趁着五一假期,发个帖子。此屏幕和Arduino官方推出的1.8寸屏几乎一样,要说有不一样的地方,一是没带TF卡座,二是印字和官方略有不同。其余都可依照官方示例进行操作。
( {/ q8 J) ~& a+ z' ?) [# C. gArduino Zion板,SPI接口                        
3 `# I" M: m+ B! X0 V( b  MOSI对应PORTB的26
8 I2 I: q+ V6 i' G. n; G9 R  MISO对应PORTB的279 i5 {' u" ]5 o3 h& w
  SCK 对应PORTB的25+ v% E; `6 [9 G9 z& x2 G4 h/ u
这个液晶屏通过SPI接口与ArduinoZion连接,连接方式如下:
% i: B* D8 m0 Q+ h+ R7 L' W$ |4 y  O
+ B, m) a7 ?, O2 t0 f  E液晶屏管脚               ArduinoZion
# F( k3 o3 U, |4 [contral-------------3.3v背光控制 可以PWM调光
$ G9 V1 Y9 N( I: gsda----------------(26)MOSI不可更改8 L2 ]$ B1 v9 u$ F: y
sck----------------(25)SCK不可更改
2 P) V6 M5 x# \reset--------------(8)可以更改管脚
. S& N$ E2 M, G/ o+ ars-----------------(9)可以更改管脚+ o# {' E- _3 Y* Z8 e+ t, a
cs-----------------(10)可以更改管脚2 W$ F4 |& e  i5 I
连接完毕,然后打开Arduino IDE的文件>示例程序>TFT>Arduino>TFT Display text,你可以看到如下程序:' Y3 ~+ Z  d4 g# S; @+ u
/*
1 R- V* I, @+ ]" w- k  Arduino TFT text example+ c9 N  ?' B  k0 n- Y/ D7 C
  7 T" B+ ]' w! q) A
  This example demonstrates how to draw text on the 9 J0 C7 m9 t  y) i8 H/ }& l7 e
  TFT with an Arduino. The Arduino reads the value 2 o& ]. F0 {  D' d; g4 F
  of an analog sensor attached to pin A0, and writes 6 L  [  k2 T% r/ P1 G5 z3 I$ o
  the value to the LCD screen, updating every
' W" f+ x8 y: W, ^2 [' J( P- @$ _  quarter second.( X4 a7 o0 I( ^8 G/ v( m# k2 n
  + Q6 M8 ~% A  m+ l6 s
  This example code is in the public domain6 p- S0 C9 V; ~% O/ d
  Created 15 April 2013 by Scott Fitzgerald
+ ~/ y! d* g# k: U, G9 }! b5 j . `2 T' P( s% Y
  http://arduino.cc/en/Tutorial/TFTDisplayText
& E& o5 Z; D  C' t: Z9 Y ' B; h* N0 s8 a4 G6 t* L
*/
, e6 y9 {0 z( W#include <TFT.h>  // Arduino LCD library
: \8 ?9 S1 q) v  l. ^' ^2 C#include <SPI.h>. L) n2 @) {  R: p, t2 m! m3 J
// pin definition for the Uno* @4 {  y$ I- D: U  G1 _- n+ \1 G
#define cs   10
, w5 T) O3 ~* @$ `' r, n6 ?#define dc   9$ B& Q8 ~' E( |" q
#define rst  8  
- M3 p, }9 G4 d: r' R; P// pin definition for the Leonardo
* t' R+ ^( j  j0 N( W! L// #define cs   7. o$ q& b, Y9 K4 L8 V
// #define dc   0, q( i# T) D- v  d% O4 h8 A
// #define rst  1 ) Y  }- M  f* ^! \* N9 c
// create an instance of the library
) l* c+ r- C( nTFT TFTscreen = TFT(cs, dc, rst);* b0 w, v8 \6 H* n/ X
// char array to print to the screen/ s9 @! ?5 a4 ]. c' F$ v
char sensorPrintout[4];
3 N: v3 r/ ?5 \7 D) ?void setup() {# n' I3 g& T" b, C7 X) ~% ]4 y/ y
  
7 `; S6 l7 t* M: {( ]  P" K  // Put this line at the beginning of every sketch that uses the GLCD:
8 C# E, u' q5 D* W. O  TFTscreen.begin();
, F6 _$ J% t# ~# i" Y, Y7 _  // clear the screen with a black background6 i$ x; ^, r, X/ V! I5 R1 _
  TFTscreen.background(0, 0, 0);5 H  m/ \& z2 ^% p1 r; S
  2 i% R0 V) n9 |: Q
  // write the static text to the screen
# h& T/ N; C6 ]. e) e  // set the font color to white
( x5 z+ O; A( a# `  TFTscreen.stroke(255,255,255);
/ n4 T8 W! K, B& r( m3 k  // set the font size, q, ^& n$ C; m+ I
  TFTscreen.setTextSize(2);2 W( ?5 r9 G+ Q- u& j
  // write the text to the top left corner of the screen
! z' g# N8 M7 y  H& Q% N  TFTscreen.text("Sensor Value :\n ",0,0);
& E1 Z2 P# D3 F) d* n  // ste the font size very large for the loop
: P) |: _2 Q# G  TFTscreen.setTextSize(5);
7 G% v+ d, j; @& v}$ d1 p# k' Q% G
void loop() {- K7 F. k: ~2 G: n; N. Q  I6 G
  // Read the value of the sensor on A0
  f$ j: y8 K* F, n" Y  String sensorVal = String(analogRead(A0));9 d, c5 g9 r1 X" r. l# C$ H1 X2 n

; D* n; g4 a  ^; y, T+ X. J, h  // convert the reading to a char array
+ S. t1 |1 {( B9 l" x  sensorVal.toCharArray(sensorPrintout, 4);
5 ^9 T1 l- y; ~4 r8 v  // set the font color
9 p/ \+ X3 r6 _# x- l  TFTscreen.stroke(255,255,255);
' p( `( B& _  e/ K- P5 `  // print the sensor value- F  Y6 m) _' @
  TFTscreen.text(sensorPrintout, 0, 20);
9 E* j( T' w( ~- o2 Y+ F  // wait for a moment! @; T5 M" R2 f
  delay(250);
" Y2 ?" a6 [9 q0 K  // erase the text you just wrote0 x2 b* u' m/ U$ d
  TFTscreen.stroke(0,0,0);& E7 D( |; ~% E8 m! T/ c
  TFTscreen.text(sensorPrintout, 0, 20);% |! \: J9 B0 n9 e3 e+ F$ G
}  F5 B+ {, }! f1 T" s' t3 r
直接下载就可以看到显示的图形,还有几个示例都可以试一下,里边示例有使用TF卡的那就只能外接卡座了,呵呵,可以开心的玩耍了
6 f2 b% _; u- P% S, z. H  G! r0 C! a. a: H
% H# o. C+ w/ q4 v

5 }( c. t$ B# t/ r4 c3 u) z6 @3 g3 u8 u

1 a9 f5 C7 U6 e
发表于 2015-5-2 09:05 | 显示全部楼层
不错,不错,写楼主分享哈
回复

使用道具 举报

发表于 2015-5-14 08:41 | 显示全部楼层
谢谢,我也有这块屏。
回复

使用道具 举报

本版积分规则

QQ|一淘宝店|手机版|商店|一乐电子 ( 粤ICP备09076165号 ) 公安备案粤公网安备 44522102000183号

GMT+8, 2025-10-27 16:07 , Processed in 0.029904 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

快速回复 返回顶部 返回列表