-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathimage.py
More file actions
68 lines (64 loc) · 2.12 KB
/
image.py
File metadata and controls
68 lines (64 loc) · 2.12 KB
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
68
from PIL import Image
import RPi.GPIO as GPIO
from spidev import SpiDev
import time
import ILI9486 as LCD
import config
spi: SpiDev = None
if __name__ == '__main__':
try:
GPIO.setmode(GPIO.BCM)
spi = SpiDev(config.SPI_BUS, config.SPI_DEVICE)
spi.mode = 0b10 # [CPOL|CPHA] -> polarity 1, phase 0
# default value
# spi.lsbfirst = False # set to MSB_FIRST / most significant bit first
spi.max_speed_hz = 64000000
lcd = LCD.ILI9486(dc=config.DC_PIN, rst=config.RST_PIN, spi=spi).begin()
print(f'Initialized display with landscape mode = {lcd.is_landscape()} and dimensions {lcd.dimensions()}')
print('Loading image...')
image = Image.open('sample.png')
width, height = image.size
partial = image.resize((width // 2, height // 2))
while True:
print('Drawing image')
lcd.display(image)
time.sleep(1)
print('Drawing partial image')
lcd.display(partial)
time.sleep(1)
print('Turning on inverted mode')
lcd.invert()
time.sleep(1)
print('Turning off inverted mode')
lcd.invert(False)
time.sleep(1)
print('Turning off display')
lcd.off()
time.sleep(1)
print('Turning on display')
lcd.on()
time.sleep(1)
print('Turning on idle mode')
lcd.idle()
time.sleep(1)
print('Turning off idle mode')
lcd.idle(False)
time.sleep(1)
print('Clearing display')
lcd.clear().display()
time.sleep(1)
print('Resetting display')
lcd.begin()
time.sleep(1)
print('Turning on sleep mode')
lcd.sleep()
time.sleep(1)
print('Turning off sleep mode')
lcd.wake_up()
time.sleep(1)
except KeyboardInterrupt:
# catching keyboard interrupt to exit, but do the cleanup in finally block
pass
finally:
GPIO.cleanup()
spi.close()