一乐电子

一乐电子百科

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

QQ登录

只需一步,快速开始

快捷登录

手机号码,快捷登录

搜索
查看: 4263|回复: 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卡座,二是印字和官方略有不同。其余都可依照官方示例进行操作。
$ ~% s9 B3 |- \1 IArduino Zion板,SPI接口                         . l7 n' c" H$ ^
  MOSI对应PORTB的26- i; A$ s5 s6 d! q
  MISO对应PORTB的27
  o% l5 K' n$ S! U# e0 P  SCK 对应PORTB的253 \6 z; v3 T% p8 I
这个液晶屏通过SPI接口与ArduinoZion连接,连接方式如下:
+ F' t7 ~4 R; X$ y) r& ~/ @
! d1 v5 c" E2 y: q: `3 x" `液晶屏管脚               ArduinoZion
+ K8 w; @. ]. U  _8 Y% econtral-------------3.3v背光控制 可以PWM调光& u# ]& {- H/ d" U
sda----------------(26)MOSI不可更改
+ Z* z1 J, _5 J/ m6 hsck----------------(25)SCK不可更改1 y2 A2 p6 V) M. _3 M( p
reset--------------(8)可以更改管脚
. o7 U& X0 L0 H$ Urs-----------------(9)可以更改管脚+ w+ A/ o; x$ V# w2 o
cs-----------------(10)可以更改管脚* }8 V; c, |; {0 _
连接完毕,然后打开Arduino IDE的文件>示例程序>TFT>Arduino>TFT Display text,你可以看到如下程序:
7 `( e$ c0 e, j2 q7 {* z/*
& p+ X1 v5 J/ e2 I+ a) u  Arduino TFT text example# R* z" e$ W0 ]# A
  
& D5 V5 |6 m3 l8 r  This example demonstrates how to draw text on the
  C- L; k6 r$ B+ ]/ N. w  TFT with an Arduino. The Arduino reads the value 6 J  a% o' d6 ?* }0 l
  of an analog sensor attached to pin A0, and writes
) d; n7 ?1 d1 C. |+ }  the value to the LCD screen, updating every6 F. T4 v0 J- v  J6 N
  quarter second.
* S6 i+ r$ R' m  t  
/ I4 B/ _, c* y" }/ C  This example code is in the public domain! ?" E% e) B0 Y
  Created 15 April 2013 by Scott Fitzgerald
* z9 N0 [. E! d+ ? 9 g2 ^% d" H* Y$ o, d8 k6 V: ]2 g- [
  http://arduino.cc/en/Tutorial/TFTDisplayText' r# q- R! |* {0 j, M

4 T. Q# k. R/ {$ }" H9 R( p" T' t' ` */
2 @: J1 {5 W% Q#include <TFT.h>  // Arduino LCD library5 J. s0 e6 z+ c' L& b
#include <SPI.h>  b7 y' ~& U, e# U7 W
// pin definition for the Uno
5 ?% j. d& s3 U$ H0 M#define cs   106 b+ f2 U; f% \8 s, i
#define dc   9
6 L% |. z( s. g* s% z7 Z" Z6 _#define rst  8  ' M0 s& c- c, J1 {
// pin definition for the Leonardo4 f4 P: [) a9 `5 |
// #define cs   7
% [4 A. I2 u* g  |: \4 N9 A: n// #define dc   0
8 L$ _' @6 y, Z' K// #define rst  1 - o% M9 n% y, g5 p
// create an instance of the library
4 f' Q; `8 ]4 Z! w! ~5 P  t) U: s2 K# FTFT TFTscreen = TFT(cs, dc, rst);
: @# W4 ]1 w4 ]" L" n# D// char array to print to the screen
7 f: e9 r% x/ ^0 l# A1 xchar sensorPrintout[4];. ?! }7 u+ ~# A( l% {
void setup() {5 \8 [. o% S4 u: ]) _
  * E" v+ E# [' B
  // Put this line at the beginning of every sketch that uses the GLCD:2 }4 ]6 C4 E# K  b, y$ ?  o& G8 @
  TFTscreen.begin();8 I" b$ K& l, @# i$ j9 K
  // clear the screen with a black background
, V1 i: R9 g$ x: A4 c  TFTscreen.background(0, 0, 0);
! F: L: y. C& ]( c. q: A! ?  " \8 I9 \( U( U! y( p* [: U$ _4 I/ J
  // write the static text to the screen
" w7 E* C, z* H3 `: m1 ?. K3 D  // set the font color to white
1 X' _) x$ \& D* q  TFTscreen.stroke(255,255,255);+ f: C& w$ T9 X
  // set the font size
+ @9 n! m# R& E# N3 r  TFTscreen.setTextSize(2);2 b  V$ k3 }; V
  // write the text to the top left corner of the screen
/ ]8 p; m2 P2 b$ f& I4 n  [6 L  TFTscreen.text("Sensor Value :\n ",0,0);
. c: I2 _0 @; F+ t4 F. g  // ste the font size very large for the loop
, j: D. `( t6 Z' i3 M  TFTscreen.setTextSize(5);
) K6 }0 C0 @% C- H: n$ F}
( R4 `/ \" z: ^+ E9 B7 |+ l5 c% s  H0 Svoid loop() {
- @& J/ ~0 D* w) P, o: `4 [. D  // Read the value of the sensor on A0
3 x0 e- P/ k0 ?! i/ r' c  String sensorVal = String(analogRead(A0));
+ o5 U7 }0 u, l  g' D
# U: N: ?* o* x8 G* Q( X  // convert the reading to a char array. x' U  }: E8 b6 r7 f+ k& r
  sensorVal.toCharArray(sensorPrintout, 4);
0 x4 Z4 [: u$ o  I( Q% e% V  // set the font color
9 W- M* @( z$ k! [3 {; M  TFTscreen.stroke(255,255,255);
9 J, l0 F+ J( X" A  // print the sensor value
- U# ^& B; r7 p  TFTscreen.text(sensorPrintout, 0, 20);( j$ f+ k7 @2 y" \
  // wait for a moment/ C  R- Y9 {5 ]/ X1 C. k' A% D
  delay(250);  W8 P+ \* }. A  L  M8 {$ [! N. g: b
  // erase the text you just wrote
- b/ Z+ x/ W! b* X7 D# A; A, `+ s  TFTscreen.stroke(0,0,0);0 A- x9 Q5 }% a
  TFTscreen.text(sensorPrintout, 0, 20);* P  W+ r4 e. ~6 K) @# y0 t6 ]0 ]
}/ g# k2 B, v0 w5 f) P
直接下载就可以看到显示的图形,还有几个示例都可以试一下,里边示例有使用TF卡的那就只能外接卡座了,呵呵,可以开心的玩耍了
6 h3 \: Y0 D; t1 e4 ^8 v) t% M, N' u; b' u, F4 b1 C
7 C. \2 w! C1 h) N
& q7 e( ^1 [* _& V' u& W: T. Y( E

% w) Q6 M( o" _
5 }( k+ N) R( ?1 ^
发表于 2015-5-2 09:05 | 显示全部楼层
不错,不错,写楼主分享哈
发表于 2015-5-14 08:41 | 显示全部楼层
谢谢,我也有这块屏。

本版积分规则

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

GMT+8, 2025-4-28 17:26 , Processed in 0.043905 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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