一乐电子

一乐电子百科

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

QQ登录

只需一步,快速开始

快捷登录

手机号码,快捷登录

搜索
查看: 3479|回复: 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卡座,二是印字和官方略有不同。其余都可依照官方示例进行操作。' X1 S$ z, A9 |( P' d
Arduino Zion板,SPI接口                         1 w* C! @6 c3 n0 z  m
  MOSI对应PORTB的266 t. m! m5 a" k9 A5 N
  MISO对应PORTB的27
3 S; y4 W3 ]  b9 z- n2 U  SCK 对应PORTB的25
4 y( q; u+ m# s8 M6 g. W6 r8 K这个液晶屏通过SPI接口与ArduinoZion连接,连接方式如下:; i% P# Y7 H( H, f% \# I( j' P

# k( B" a5 Y$ p液晶屏管脚               ArduinoZion  q6 N# G5 a4 `( I( z! p
contral-------------3.3v背光控制 可以PWM调光2 f2 X& k- h1 L6 s6 P: E
sda----------------(26)MOSI不可更改
0 j0 T% u+ o  _sck----------------(25)SCK不可更改/ g% R+ j1 ?0 D. ^1 b
reset--------------(8)可以更改管脚2 i* e" }4 v9 q2 p
rs-----------------(9)可以更改管脚
$ m' R% ^% B- {; mcs-----------------(10)可以更改管脚8 A; @6 `8 _. L* r: {1 X6 z) ]0 O
连接完毕,然后打开Arduino IDE的文件>示例程序>TFT>Arduino>TFT Display text,你可以看到如下程序:: |, U9 `2 f4 B7 Z
/*- W: L7 b2 K/ Q+ S1 m
  Arduino TFT text example8 Q# H% c5 ?2 k# \, K, W
  - Q8 |3 n+ |0 @3 U% e8 |1 D
  This example demonstrates how to draw text on the ) b( x0 I0 }+ X  I! \
  TFT with an Arduino. The Arduino reads the value
4 f6 \  L7 Y, ^3 l5 H/ Z  of an analog sensor attached to pin A0, and writes
* f4 O9 {" U4 C6 f4 U' o  the value to the LCD screen, updating every3 t* k* l  S$ @3 I0 r
  quarter second.7 ]! n4 o4 w0 _9 U4 u
  " t# a1 s5 ^' c2 |5 V$ Y
  This example code is in the public domain, V6 s5 u3 |* E$ i$ f
  Created 15 April 2013 by Scott Fitzgerald
) _% y+ F. e0 {2 }5 G ; Z/ K9 U* g4 q5 f4 ]5 N
  http://arduino.cc/en/Tutorial/TFTDisplayText" d8 C% K  i$ K+ ]2 q
1 d/ I) ^3 X: A! f$ B) [6 L
*// U% f. K3 ?: Y' ~0 s0 U1 w
#include <TFT.h>  // Arduino LCD library
" J, C  c9 N9 G$ C- c1 q5 I$ g% J#include <SPI.h>; ?8 A/ q0 K/ o: [1 e
// pin definition for the Uno+ [6 n: }8 c7 B, i4 I  ]* T( _
#define cs   10% T5 l0 l* W1 S& f
#define dc   9
0 _( {7 I4 P- T/ V- k& s  A#define rst  8  5 S0 B. W, }0 E
// pin definition for the Leonardo: q7 `$ K1 j- r4 ?+ I" s
// #define cs   7
  x- U4 Z7 q9 T* C// #define dc   0
& z" |  ^" O  l// #define rst  1   F9 X" V) ], {: d: R: x; E
// create an instance of the library1 k. \( j7 x  }$ X- j/ i
TFT TFTscreen = TFT(cs, dc, rst);$ `2 v) R6 N" _# x+ f! C
// char array to print to the screen" L8 b$ e1 b4 E. n7 H
char sensorPrintout[4];# ?2 X& [# ]1 W( D9 Q4 v9 s
void setup() {* K( \' b: R( a$ C
  - T8 V* G9 f, v7 C$ _! T+ [
  // Put this line at the beginning of every sketch that uses the GLCD:  v! H/ F0 W2 x6 O' o$ ?7 W% `
  TFTscreen.begin();
. F: n( g4 c! I6 m  g8 Q. W. o( y  // clear the screen with a black background4 g: f9 P9 B- ]8 B3 F' g3 f" g
  TFTscreen.background(0, 0, 0);
9 D8 @1 H% s( t  2 {' B0 H( ~0 s
  // write the static text to the screen% N( i+ ~8 A! Q1 ]& W9 X
  // set the font color to white5 [  v+ ?5 z3 b) j# s# @* w7 A1 Y" j3 Y
  TFTscreen.stroke(255,255,255);
& _: O/ @: b$ S5 s$ a: T  // set the font size; T: {, b( r& f* b5 X3 v
  TFTscreen.setTextSize(2);
( Y2 Q0 O' a1 H  // write the text to the top left corner of the screen5 P2 c/ w. U* T! M9 R+ q
  TFTscreen.text("Sensor Value :\n ",0,0);5 B9 ^. ]  k+ ]7 n7 l& W& Q
  // ste the font size very large for the loop0 O% |) u. ~  B+ w% H5 e7 _2 x  Q  F
  TFTscreen.setTextSize(5);; X! I& M* u  z4 c5 ~
}# T& Z  E4 \% r( R
void loop() {
) H% ~: R6 ~5 t- O3 X& C& o  // Read the value of the sensor on A0
. D4 C/ D" O# e8 l4 H4 O  String sensorVal = String(analogRead(A0));
: Q# O% C5 L) O ( A7 Y' ~- D/ V% m' R7 Q0 E
  // convert the reading to a char array
+ g3 A: g9 ~7 j4 J  sensorVal.toCharArray(sensorPrintout, 4);
, ], }2 ]3 B8 ]' j8 u5 d  // set the font color2 L( e5 c: x9 H3 N+ s4 W
  TFTscreen.stroke(255,255,255);
" J# P8 b6 ]3 b  // print the sensor value
0 w; e3 p) t  J! V6 k" Z' w) s  TFTscreen.text(sensorPrintout, 0, 20);5 A3 [5 G: j4 i& w, H
  // wait for a moment$ \" b/ C2 L4 K0 j
  delay(250);
$ e% a% V7 r0 v; D  // erase the text you just wrote$ Q& y0 i: ?- S
  TFTscreen.stroke(0,0,0);
9 z' n1 |2 c8 M9 o) |# m- R7 ?  TFTscreen.text(sensorPrintout, 0, 20);
% m; A. E$ M6 a% p  N}0 J* m6 G& I( T$ |& s
直接下载就可以看到显示的图形,还有几个示例都可以试一下,里边示例有使用TF卡的那就只能外接卡座了,呵呵,可以开心的玩耍了  u/ ~( \( _4 y; Y
) e6 l8 I; G4 j/ O% C8 c

- @! L. ?# T6 q+ D) M$ L1 s# z# s
$ l/ ~4 Y  g. v+ r! a7 E4 Y3 Q
8 h( @4 T1 p" Z5 v) i! n
+ h8 _' Q  U: z+ F! b5 R# T
发表于 2015-5-2 09:05 | 显示全部楼层
不错,不错,写楼主分享哈
发表于 2015-5-14 08:41 | 显示全部楼层
谢谢,我也有这块屏。

本版积分规则

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

GMT+8, 2024-5-10 17:36 , Processed in 0.064237 second(s), 32 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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