一乐电子

一乐电子百科

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

QQ登录

只需一步,快速开始

快捷登录

手机号码,快捷登录

搜索
查看: 3502|回复: 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卡座,二是印字和官方略有不同。其余都可依照官方示例进行操作。, ?7 f+ |! t3 f& Z4 j
Arduino Zion板,SPI接口                        
8 g6 a' ]( b/ A4 ^, F  MOSI对应PORTB的265 R8 o/ W7 _) ]4 u- k
  MISO对应PORTB的27
% I- d0 r$ L; ?& B  SCK 对应PORTB的256 @, I/ W9 o: ?( @) G4 n
这个液晶屏通过SPI接口与ArduinoZion连接,连接方式如下:
" W+ I1 w! y5 t2 c& I1 d1 C( N8 t- U1 [# }9 _4 g2 X# E1 F
液晶屏管脚               ArduinoZion
5 x: [5 M7 R" `$ @- g4 Zcontral-------------3.3v背光控制 可以PWM调光' M, V3 i4 o1 `$ ^! v: ]3 x
sda----------------(26)MOSI不可更改( q: D( x0 `; q! ^
sck----------------(25)SCK不可更改
4 J, l% n# v% j( d* R0 ~reset--------------(8)可以更改管脚
; Z% Y$ M; C( }- Jrs-----------------(9)可以更改管脚( T" c. P: g/ ?1 X6 p/ V  `. F
cs-----------------(10)可以更改管脚
7 s# X. n% T: _& B连接完毕,然后打开Arduino IDE的文件>示例程序>TFT>Arduino>TFT Display text,你可以看到如下程序:
, V$ B% l5 ^5 h0 }0 x2 v9 ?/*
2 C" `) d* B! d5 s/ X" q# p  Arduino TFT text example
- H4 j0 p8 S3 `3 V1 q& T  
. f* M: o! ?! J$ u  This example demonstrates how to draw text on the
; V: w( g1 F; F7 j: i9 D* F; r; T  TFT with an Arduino. The Arduino reads the value # z: q) G# I% Y8 [
  of an analog sensor attached to pin A0, and writes
" `, u" E: G3 l, |: R0 |  the value to the LCD screen, updating every
+ a  p! o4 C1 Q  quarter second.
+ A: `' b/ b0 K$ ?7 d+ q) Y( n2 s" H/ L  
: R" X! v, B+ Z" `  This example code is in the public domain- B4 k+ d! W6 C( J
  Created 15 April 2013 by Scott Fitzgerald1 _( k9 Q0 D: S$ t: f3 T

- ?, u; S& K: N9 C& E$ C  http://arduino.cc/en/Tutorial/TFTDisplayText" k5 w, |' B7 N2 ^9 }4 Q
6 P! f% r, w3 ^1 V! Q4 D3 D. e$ H; ?
*/
4 m( l1 O" p1 N5 E, W4 [5 I#include <TFT.h>  // Arduino LCD library% J" O: J5 ^" D# n: j
#include <SPI.h>8 T- Q  d7 A8 \) J6 H1 x# y
// pin definition for the Uno
3 z5 d) o  o! F' O2 X& \#define cs   10
0 p' g! `. m$ Y* H$ Y#define dc   96 w0 m: O% f) o% ?2 R- z+ e
#define rst  8  
. X! \% M7 ^7 Z2 h+ g// pin definition for the Leonardo
  A0 w$ `6 Q; D+ [// #define cs   7
& J) @. |) Q$ O. A/ k7 E! q// #define dc   0
  f* v: F" i) U/ `5 ~// #define rst  1
8 a9 e# b; \, }9 M! ?& c/ I1 c- r// create an instance of the library9 @1 u! m2 t# g/ ^
TFT TFTscreen = TFT(cs, dc, rst);
9 a, j0 G; _8 I* ^// char array to print to the screen
3 U" ~& Q: B4 x, v$ Zchar sensorPrintout[4];: a+ r0 i! B. r* _
void setup() {+ f- B& x* I* v' v5 I* |, L
  
9 W. p& x- U7 ^  // Put this line at the beginning of every sketch that uses the GLCD:" Q: t% J* g0 B$ Q, }4 J
  TFTscreen.begin();
2 W& N2 w7 m1 @& H2 G- T  // clear the screen with a black background
6 ^# ?- I  L: A, m6 f7 r* j  TFTscreen.background(0, 0, 0);
4 V5 n/ ]7 l7 G# H  
2 e" Y/ N# l0 i, z5 s  // write the static text to the screen
! c2 N4 @1 {$ Q! |9 m! z! B  // set the font color to white
$ f# A* c+ S+ G  TFTscreen.stroke(255,255,255);: y' t, f( p; ?. u4 O
  // set the font size" N- X- m# ^6 P% _1 c; x4 [
  TFTscreen.setTextSize(2);
* k1 l( ]' m$ g, v2 K% k  // write the text to the top left corner of the screen5 {9 y7 q* D: t; b
  TFTscreen.text("Sensor Value :\n ",0,0);
: a. x- B4 ]0 d( G0 B  // ste the font size very large for the loop
# K( ^1 C5 }" C% S. r, [  TFTscreen.setTextSize(5);
! b! \9 f! j7 `/ o}
4 |; e/ A  [( }void loop() {
$ y% {0 N' W4 N3 @$ _0 ?  // Read the value of the sensor on A0
$ o! X! D: o* C% Y" A9 X# @: m  String sensorVal = String(analogRead(A0));
% n# T& V. |8 e3 T  `* Z
# D  E! H9 [$ n3 R5 {  // convert the reading to a char array
, D& F5 ~' S0 H  sensorVal.toCharArray(sensorPrintout, 4);0 ~2 W; l* R, P; j7 V, G
  // set the font color$ v& R- y$ y+ k- v1 ^( G; Y
  TFTscreen.stroke(255,255,255);+ P% d/ [0 L9 Z8 G) o
  // print the sensor value/ j/ G) S+ q8 U! K
  TFTscreen.text(sensorPrintout, 0, 20);. ]& m) |" h; G" b
  // wait for a moment
  X% S! q  |& T% e0 i0 g% |  delay(250);# {& U# L* r6 D* M+ f# i& B4 t! }
  // erase the text you just wrote
$ u' |4 A' t1 ~3 X4 g  TFTscreen.stroke(0,0,0);) L/ U( X1 f2 I. @- r( \4 G. k
  TFTscreen.text(sensorPrintout, 0, 20);
$ h* J( N+ r" X- s2 {: V; g1 P}
  d. P5 z6 H9 L/ h' R3 p- p/ W. V+ @/ ^& P直接下载就可以看到显示的图形,还有几个示例都可以试一下,里边示例有使用TF卡的那就只能外接卡座了,呵呵,可以开心的玩耍了
* a! F3 p& C* c3 K( t
$ G1 S4 A, ?, Q. y9 \, ?6 f8 k( e; l% T9 A5 D1 {

5 {( O# p% a# t; e* Q. ~% h6 f/ I0 ?/ ~* B! g( y

1 F& T; C+ F; s$ P: G. ^" }
发表于 2015-5-2 09:05 | 显示全部楼层
不错,不错,写楼主分享哈
发表于 2015-5-14 08:41 | 显示全部楼层
谢谢,我也有这块屏。

本版积分规则

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

GMT+8, 2024-5-18 05:28 , Processed in 0.064621 second(s), 32 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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