一乐电子

一乐电子百科

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

QQ登录

只需一步,快速开始

快捷登录

手机号码,快捷登录

搜索
查看: 3503|回复: 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卡座,二是印字和官方略有不同。其余都可依照官方示例进行操作。
0 z3 q0 M' g7 q9 p+ o* |$ MArduino Zion板,SPI接口                        
, F1 w- v1 w. {) l& ?/ r  MOSI对应PORTB的26+ J5 {6 T+ \: g$ x4 J3 J+ C
  MISO对应PORTB的27# y& w1 V9 I9 E3 m- {
  SCK 对应PORTB的25
) r" Y8 N6 d5 C" i0 `) p这个液晶屏通过SPI接口与ArduinoZion连接,连接方式如下:
* y( M0 J0 l5 Y- O# j9 m) U
! N- f4 [3 ^" E' ?; z6 f液晶屏管脚               ArduinoZion% ^; E8 O2 U2 `
contral-------------3.3v背光控制 可以PWM调光% e3 M! _; e7 _2 D4 w7 e& K( J0 w
sda----------------(26)MOSI不可更改1 h/ w2 F3 @% |/ o
sck----------------(25)SCK不可更改7 b& F; F4 K" F7 o' k* r
reset--------------(8)可以更改管脚5 r7 g( Y. a, a& {: ]& c6 x) f
rs-----------------(9)可以更改管脚
& k* b2 \# c6 |0 g/ Y2 Ocs-----------------(10)可以更改管脚0 ?- N3 ~6 X) b% M( h
连接完毕,然后打开Arduino IDE的文件>示例程序>TFT>Arduino>TFT Display text,你可以看到如下程序:
/ e+ u, M( Y- g% m* j& q/*7 j! X% k# s/ G. D+ {! R
  Arduino TFT text example
. q4 c4 ?) ]2 G  q% B0 y) H  
1 R" r) G' C. P, b; d5 g2 b7 ?  This example demonstrates how to draw text on the 1 r5 n8 o5 C+ O
  TFT with an Arduino. The Arduino reads the value ' j/ c# f" G4 J* }
  of an analog sensor attached to pin A0, and writes
8 A- `) H' _7 Y  the value to the LCD screen, updating every
  @3 V; e# {! D. d' N1 g  quarter second.0 U- m6 i  j( f7 G
  ! h$ W; C- Y4 Q: a: E& E! D
  This example code is in the public domain
$ e3 C5 t& G, W, ]+ F* R  Created 15 April 2013 by Scott Fitzgerald1 T' b4 s' T/ b+ G) ~; s8 l

0 Z* W9 S  O- b4 v0 ]6 m3 j5 M2 r  http://arduino.cc/en/Tutorial/TFTDisplayText
( m+ z/ E" M" d: p: p/ F 5 |' X* U$ n# R) `! X
*/
: v7 T9 T5 j1 |- Q0 m3 S8 R* e) P#include <TFT.h>  // Arduino LCD library
, J9 y+ X3 H4 \: b#include <SPI.h>) o  x9 S* n: X# o- [  E0 D6 s
// pin definition for the Uno, H+ q" t: n. J& s+ Q
#define cs   10! u. X+ B9 q, k
#define dc   92 _% G( D; F3 n! [8 c- E
#define rst  8  
( @+ i8 ]- ?" [" L// pin definition for the Leonardo
0 t, y" J! L4 }* W5 g! H' v6 m// #define cs   7
" ?1 y% n) G9 K  s3 c// #define dc   0
, L+ j3 T6 }) b6 U4 y5 R// #define rst  1 , Q4 U' J; x2 z# ?0 A
// create an instance of the library0 i6 _$ t4 h& H! A9 ^
TFT TFTscreen = TFT(cs, dc, rst);
' B3 o. D" q7 |// char array to print to the screen4 T( [; H. Y+ F& T
char sensorPrintout[4];
: M% o% s5 i3 z4 M, [void setup() {
. H! @" Y6 t/ Q* G  " D1 e6 B- a9 L( V+ G
  // Put this line at the beginning of every sketch that uses the GLCD:. S$ N# c5 }* m; G
  TFTscreen.begin();' T3 D4 m- q1 j/ I) r
  // clear the screen with a black background! s* f, N, u0 E+ B5 N3 O
  TFTscreen.background(0, 0, 0);
1 F9 Z- n/ v2 p6 b1 y  + Z# w& i! ^' V5 C0 I
  // write the static text to the screen* d. N' Q$ e2 G6 F
  // set the font color to white
" \! S+ I  u7 `  L# }$ f  TFTscreen.stroke(255,255,255);
; I% M3 W/ d* k* H; N  // set the font size
/ ~; S( \: [/ t4 T# q: Q  h  TFTscreen.setTextSize(2);6 `8 E7 t, ^) h$ C8 u+ d
  // write the text to the top left corner of the screen
1 y) g& z% v! _! g0 q  TFTscreen.text("Sensor Value :\n ",0,0);
( q$ `% `* {  J  // ste the font size very large for the loop
5 r- @0 ^& R7 P: N8 ?" U4 g  TFTscreen.setTextSize(5);
  G  v& v2 c8 ^& \% H9 [}+ \: e' v( ?/ c( L& R% i
void loop() {
! u& p8 J- v; z' h7 Y5 }6 H+ u  // Read the value of the sensor on A0. Q/ S4 Q9 j6 |% E+ s
  String sensorVal = String(analogRead(A0));( W7 Z3 C8 g/ n: w1 k' b' G
; v; z( A6 C, [6 `; _
  // convert the reading to a char array
/ A! X, \& o% \, T& u8 E  sensorVal.toCharArray(sensorPrintout, 4);
5 T) Q, H9 e9 d$ ?  // set the font color
6 H) d. t- [5 c" \& k  TFTscreen.stroke(255,255,255);
' L2 @0 m1 \# [  // print the sensor value$ N; E  ~: Y7 Q$ H  K9 _2 q4 D8 X( D
  TFTscreen.text(sensorPrintout, 0, 20);
  _- k3 v" Q1 A5 N& [( c  // wait for a moment$ |0 V( v/ M  J8 {' [6 |
  delay(250);
+ e9 Z3 C- e  I8 Z! t$ S  // erase the text you just wrote1 \- P" H! U1 ^! U3 y4 r: |# z
  TFTscreen.stroke(0,0,0);
' m. ]# {, N; z1 }2 ]  TFTscreen.text(sensorPrintout, 0, 20);$ x: Y- k! ~5 V: v0 \
}- q+ P( f1 F  i- U
直接下载就可以看到显示的图形,还有几个示例都可以试一下,里边示例有使用TF卡的那就只能外接卡座了,呵呵,可以开心的玩耍了
* l& r$ S0 W( I+ n
) f1 i4 C- _! o; A1 N( V& q
- L6 D% B& H5 g" ]% d
' i7 j# U/ H# }+ Y8 G' k8 ^# F- P* ~
: i6 l- ]& B  A, g
8 U% P: `# t9 D% M. e1 s
发表于 2015-5-2 09:05 | 显示全部楼层
不错,不错,写楼主分享哈
发表于 2015-5-14 08:41 | 显示全部楼层
谢谢,我也有这块屏。

本版积分规则

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

GMT+8, 2024-5-18 11:10 , Processed in 0.056296 second(s), 24 queries , Gzip On.

Powered by Discuz! X3.4

Copyright © 2001-2021, Tencent Cloud.

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