一乐电子

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

QQ登录

只需一步,快速开始

微信扫码登录

手机号码,快捷登录

手机号码,快捷登录

搜索
查看: 4943|回复: 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卡座,二是印字和官方略有不同。其余都可依照官方示例进行操作。  K8 ?; k& o8 Q; e5 d$ ?* V1 W
Arduino Zion板,SPI接口                        
: y+ ]$ K+ M; L+ m( x  MOSI对应PORTB的26; s9 h6 ]5 `& Y, L
  MISO对应PORTB的27
/ w6 B) c) |! _; U- d+ Y  SCK 对应PORTB的25
( R0 w  Z7 x' C' r9 H+ d这个液晶屏通过SPI接口与ArduinoZion连接,连接方式如下:
* O) ^, g0 h* c1 S5 g4 p5 m+ S6 I8 v9 H; U" M9 F7 I2 b& M
液晶屏管脚               ArduinoZion
2 ^! u# w, L/ M8 s" D7 Ycontral-------------3.3v背光控制 可以PWM调光
* a) e( v! G5 p- u. {# xsda----------------(26)MOSI不可更改
8 d  F, z- F- B* G3 Nsck----------------(25)SCK不可更改
( N! L2 B5 d7 d9 h2 s% G9 _reset--------------(8)可以更改管脚" K  n7 e5 v1 k6 l; L  i8 b8 V3 h: h! w
rs-----------------(9)可以更改管脚6 `7 X0 }8 {# m. `7 @
cs-----------------(10)可以更改管脚
$ i, p" Q  w" u7 H* ?4 t连接完毕,然后打开Arduino IDE的文件>示例程序>TFT>Arduino>TFT Display text,你可以看到如下程序:8 z, A# R% A. |
/*/ Y$ ]- r0 b- t; F
  Arduino TFT text example% a8 G# f6 j: U8 T4 l
  
% l2 h) H# ~; j  This example demonstrates how to draw text on the # w9 [/ e5 v- n1 G  |
  TFT with an Arduino. The Arduino reads the value 1 k. I, ?, t9 M& j. b
  of an analog sensor attached to pin A0, and writes & c% c' A1 U, F4 p- i. v# z
  the value to the LCD screen, updating every
: ^7 [7 c* }5 F# f: B# [  quarter second." ?. M8 k* Y  ]  \0 Z5 e. A' u
  
( ~5 g& C3 y% }7 S- @  This example code is in the public domain" m/ z7 V9 B. Q$ d* H. ], S
  Created 15 April 2013 by Scott Fitzgerald
( g7 a9 N+ c# f- F: x0 r7 z , a' V8 `$ P6 z5 S; @
  http://arduino.cc/en/Tutorial/TFTDisplayText
& M6 b& E+ j. Z4 C% q
2 |$ |, H% W" J/ x */
7 Y0 `2 L: t8 f. z7 l% C3 ^  B$ v#include <TFT.h>  // Arduino LCD library6 w1 F% g" d9 V
#include <SPI.h>
! T( J! K, ?% ]// pin definition for the Uno# d, I: n) o* [% G
#define cs   10
' d) L$ V1 {( g2 X: F0 \, q7 f. \* ~#define dc   9$ p. N7 w5 i3 V4 w0 \
#define rst  8  
5 C4 z2 M# `  ^! X  m+ j// pin definition for the Leonardo$ i; y* F1 F. h3 S
// #define cs   7
; F7 a" F/ L7 H' t' X; a// #define dc   0
4 s5 F+ z5 ~' o  r// #define rst  1
  I# t% d" p. Q0 C+ k5 X1 H// create an instance of the library5 C, ~$ i6 `2 |8 V
TFT TFTscreen = TFT(cs, dc, rst);
* M1 U2 v" q$ }, w, I' T/ c// char array to print to the screen/ s% M3 [5 K( n3 _( N% B9 B
char sensorPrintout[4];
) g) G: b0 z! Z  K! r6 U, Lvoid setup() {3 D! A: z2 E8 Z
  
9 X0 N6 I* N, z$ a  // Put this line at the beginning of every sketch that uses the GLCD:
7 m1 k7 y/ y+ @1 T* O1 q0 b  TFTscreen.begin();' U  ~0 L  }" _4 t: n) V
  // clear the screen with a black background" o9 g! d- u( [& l0 W9 j5 y
  TFTscreen.background(0, 0, 0);- v! \: [! Z3 \  s2 c3 O3 k, q: m
  ) w. G9 W  E" y/ P/ y
  // write the static text to the screen
3 r2 E0 h2 X# n: L, e: z; k  // set the font color to white9 j, [. \! c1 {; o# ?
  TFTscreen.stroke(255,255,255);; U$ s1 v  Z" w; g' ~
  // set the font size
- G4 C2 \" j3 T- ]  TFTscreen.setTextSize(2);9 Z/ Y* ?) H# t
  // write the text to the top left corner of the screen
; P2 l4 e- v& ?# J3 _  TFTscreen.text("Sensor Value :\n ",0,0);5 B) d. V2 S$ S! I& E
  // ste the font size very large for the loop6 F/ Y0 `. y% a' r/ @/ i
  TFTscreen.setTextSize(5);
9 I" k$ Q5 e2 ?: v; T}$ b) ~1 }) n; L: M" a
void loop() {
* Q. E3 C* h. l8 `, e! k  // Read the value of the sensor on A06 @2 P3 o  ^6 X% d$ ^; q+ u4 v
  String sensorVal = String(analogRead(A0));8 \; I& I$ ^' V) X* H  e  G

: `% A$ |& E9 `  // convert the reading to a char array% Q; C4 |* S+ {0 @0 o  k
  sensorVal.toCharArray(sensorPrintout, 4);
. y7 U+ a* Z( R2 H" E  // set the font color" c2 w7 R4 J, a  }; t" n
  TFTscreen.stroke(255,255,255);% m& f$ J2 c8 z5 n% x8 H, B0 [
  // print the sensor value
4 R" q4 J! n- _  TFTscreen.text(sensorPrintout, 0, 20);/ s* f3 S4 z! T; A  x/ Y& {
  // wait for a moment0 y6 z8 `' |( C* ?- w7 T- N. U
  delay(250);+ X" [* v& x, J( {. G
  // erase the text you just wrote
, I+ \# U: @# e. c  TFTscreen.stroke(0,0,0);
1 [0 g" R( x( U  d+ \  L' X  TFTscreen.text(sensorPrintout, 0, 20);
9 C5 P+ F& a- d$ Z! r}
" ~4 O8 Y# }7 @. G6 i% {' ?! }直接下载就可以看到显示的图形,还有几个示例都可以试一下,里边示例有使用TF卡的那就只能外接卡座了,呵呵,可以开心的玩耍了! ?! l0 N) N! m$ U
- K8 U. t) N- j) \8 g( l9 E! L7 W
3 H" h8 \( N7 r8 a2 A- O- r- a

* {0 J5 q5 N+ Z7 p2 I* j1 s( `+ b: {
" k* V- H8 R/ m, v2 m
" P$ q- ~. V9 g+ k" o' c5 X0 j
发表于 2015-5-2 09:05 | 显示全部楼层
不错,不错,写楼主分享哈
回复

使用道具 举报

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

使用道具 举报

本版积分规则

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

GMT+8, 2026-2-25 15:07 , Processed in 0.035031 second(s), 20 queries , Gzip On.

Powered by Discuz! X3.5

© 2001-2025 Discuz! Team.

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