forked from BLavery/LIBtft144
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathexample-tft144-rpi-only.py
67 lines (45 loc) · 1.5 KB
/
example-tft144-rpi-only.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# example-tft144.py V1.6
# Brian Lavery (C) Oct 2014 brian (at) blavery (dot) com
# Free software.
# Demonstrates the "BLACK" or "RED" 128x128 SPI TFT board
# There are 3 variants of this file:
# example-tft144.py
# example-tft144-rpi-only.py <<<<<< THIS ONE
# example-tft144-vgpio-only.py
import RPi.GPIO as GPIO
from lib_tft144 import TFT144
from time import sleep
import spidev
GPIO.setwarnings(False)
GPIO.setmode(GPIO.BCM)
RST = 18
CE = 0 # 0 or 1 for CE0 / CE1 number (NOT the pin#)
DC = 22 # Labeled on board as "A0"
LED = 23 # LED backlight sinks 10-14 mA @ 3V
# Don't forget the other 2 SPI pins SCK and MOSI (SDA)
TFT = TFT144(GPIO, spidev.SpiDev(), CE, DC, RST, LED, isRedBoard=False)
print ("Display character set:")
posx=0
posy=0
# Manual cursor moving
for i in range (32,256):
TFT.put_char(chr(i),posx,posy,TFT.WHITE,TFT.BLACK)
posx+=TFT.fontW
if (posx+TFT.fontW)>128:
posx=0
posy+=TFT.fontH
sleep(2)
TFT.clear_display(TFT.BLUE)
print ("Message:")
# Automatic cursor moving
TFT.put_string("Hello,World!",28,28,TFT.WHITE,TFT.BLUE) # std font 3 (default)
TFT.put_string("TFT144", 24,80,TFT.RED, TFT.BLUE, 4) # doubled font 4
sleep(3)
print ("Rectangle")
TFT.draw_filled_rectangle(0,0,128,64 ,TFT.RED)
TFT.draw_filled_rectangle(0,64,128,128,TFT.BLACK)
for i in range (4,32,4):
TFT.draw_rectangle(i,i,128-i,64-i,TFT.colour565(i-1,i-1,i-1))
print ("Line:")
TFT.draw_line(0,0,128,128,TFT.GREEN)
TFT.draw_line(0,128,128,0,TFT.GREEN)