/
SushiRotator_ESP8266_AQM1248A_SPI.py
130 lines (108 loc) · 2.64 KB
/
SushiRotator_ESP8266_AQM1248A_SPI.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
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
#
# Sushi rotator for ESP8266 & AQM1248A(SPI) with MicroPython
# Copyright (c) 2016 nobukuma
#
# This code is licensed under Apache v2.0 License
# (http://www.apache.org/licenses/LICENSE-2.0)
#
from machine import SPI
from machine import Pin
import time
# 寿司ビットマップデータ
from data import icon
# スクロールのオフセット
SCROLLOFFSET = 3
# 初期位置
INITIALOFFSET = -47
# SPI設定(Hardware SPI)
RSnum = 5
CSnum = 4
RS = Pin(RSnum, Pin.OUT)
CS = Pin(CSnum, Pin.OUT)
spi = SPI(1, baudrate=80000000, polarity=0, phase=0)
spi.init(baudrate=80000000)
# LCD制御
# コマンド送信
def lcdCmd(cmd):
RS.low()
CS.low()
value = cmd.to_bytes(1, 'big')
spi.write(value)
RS.high()
CS.high()
# データ送信
def lcdData(data):
RS.high()
CS.low()
value = data.to_bytes(1, 'big')
spi.write(value)
RS.high()
CS.high()
# ページ選択
def selectPage(page):
lcdCmd(0xB0 | (page & 0x0F))
# カラム選択
def selectColumn(col):
lcdCmd(0x10 | ((col >> 4) & 0x0F))
lcdCmd(0x00 | (col & 0x0F))
# ディレイ
def delay(durationInMSec):
time.sleep_ms(durationInMSec)
# 初期化処理
def initLCD():
lcdCmd(0xAE)
lcdCmd(0xA0)
lcdCmd(0xC8)
lcdCmd(0xA3)
# 内部レギュレータON
lcdCmd(0x2C)
delay(2)
lcdCmd(0x2E)
delay(2)
lcdCmd(0x2F)
# コントラスト設定
lcdCmd(0x23)
lcdCmd(0x81)
lcdCmd(0x1C)
# 表示設定
lcdCmd(0xA4)
lcdCmd(0x40)
lcdCmd(0xA6)
lcdCmd(0xAF)
# 描画処理
# x-scrolloffset .. x+47までをクリア&描画する
def drawSushi(x, scrolloffset):
for page in range(0, 6):
selectPage(page)
# x - scrolloffset .. x - 1まではクリア
for col in range(x - scrolloffset, x):
if col >= 0 and col < 128:
selectColumn(col)
lcdData(0)
# x .. x+47は描画
for col in range(x, x + 48):
selectColumn(col)
if col >= 0 and col < 128:
value = 0
for offset in range(0, 8):
row = page * 8 + offset
pixelValue = icon[row][col-x]
value = value | pixelValue << offset
lcdData(value)
# 画面の全消去
def clearAll():
for page in range(0, 6):
selectPage(page)
selectColumn(0)
for col in range(0, 128):
lcdData(0)
# メイン処理
def main():
initLCD()
clearAll()
x = INITIALOFFSET
while True:
drawSushi(x, SCROLLOFFSET)
x = x + SCROLLOFFSET
x = x if x < 128 else INITIALOFFSET
main()