-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
209 lines (179 loc) · 5.22 KB
/
Copy pathmain.py
File metadata and controls
209 lines (179 loc) · 5.22 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
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
from machine import Pin, I2C
import time
import utime
from pico_i2c_lcd import I2cLcd
from dht import DHT11, InvalidChecksum, InvalidPulseCount
I2C_ADDR = 0x27
I2C_NUM_ROWS = 4
I2C_NUM_COLS = 20
i2c = I2C(0, sda=Pin(0), scl=Pin(1), freq=400000)
lcd = I2cLcd(i2c, I2C_ADDR, I2C_NUM_ROWS, I2C_NUM_COLS)
pin = Pin(27, Pin.OUT, Pin.IN)
sensor = DHT11(pin)
arrow_up = bytearray([0, 4, 14, 31, 4, 4, 4, 0])
arrow_down = bytearray([0, 4, 4, 4, 31, 14, 4, 0])
x = bytearray([0,27,14,4,14,27,0,0])
o = bytearray([6,9,9,6,0,0,0,0])
lcd.custom_char(0, arrow_up)
lcd.custom_char(1, arrow_down)
lcd.custom_char(2, x)
lcd.custom_char(3, o)
button_up = Pin(16, Pin.IN, Pin.PULL_UP)
button_down = Pin(19, Pin.IN, Pin.PULL_UP)
button_esc = Pin(15, Pin.IN, Pin.PULL_UP)
button_enter = Pin(18, Pin.IN, Pin.PULL_UP)
menu_page = 0
max_page = 3
bluzzer = Pin(3, Pin.OUT, value=1)
def display_menu(page):
lcd.clear()
if page == 0:
lcd.move_to(0,0)
lcd.putstr("[1] Temperatura <")
lcd.move_to(0,1)
lcd.putstr("[2] Czytnik MicroSD")
lcd.move_to(0,2)
lcd.putstr("--------------------")
lcd.move_to(0,3)
lcd.putstr("[")
lcd.putchar(chr(1))
lcd.putstr("] next prev [")
lcd.putchar(chr(0))
lcd.putstr("]")
elif page == 1:
lcd.move_to(0,0)
lcd.putstr("[2] Czytnik MicroSD<")
lcd.move_to(0,1)
lcd.putstr("[3] Jasnosc")
lcd.move_to(0,2)
lcd.putstr("--------------------")
lcd.move_to(0,3)
lcd.putstr("[")
lcd.putchar(chr(1))
lcd.putstr("] next prev [")
lcd.putchar(chr(0))
lcd.putstr("]")
elif page == 2:
lcd.move_to(0,0)
lcd.putstr("[3] Jasnosc <")
lcd.move_to(0,1)
lcd.putstr("[4] Ustawienia")
lcd.move_to(0,2)
lcd.putstr("--------------------")
lcd.move_to(0,3)
lcd.putstr("[")
lcd.putchar(chr(1))
lcd.putstr("] next prev [")
lcd.putchar(chr(0))
lcd.putstr("]")
elif page == 3:
lcd.move_to(0,0)
lcd.putstr("[4] Ustawienia <")
lcd.move_to(0,1)
lcd.putstr("ZenMini v1")
lcd.move_to(0,2)
lcd.putstr("--------------------")
lcd.move_to(0,3)
lcd.putstr("[")
lcd.putchar(chr(1))
lcd.putstr("] next prev [")
lcd.putchar(chr(0))
lcd.putstr("]")
import time
from machine import Pin
def display_page_temp():
lcd.clear()
green = Pin(11, Pin.OUT)
red = Pin(12, Pin.OUT)
MIN_DELAY = 10
last_read_time = 0
while True:
if time.time() - last_read_time >= MIN_DELAY:
try:
sensor.measure()
last_read_time = time.time()
green.on()
lcd.clear()
lcd.move_to(0,0)
lcd.putstr("Temperatura: {}C".format(sensor.temperature))
lcd.move_to(0,1)
lcd.putstr("Wilgotnosc: {}%".format(sensor.humidity))
lcd.move_to(0,2)
lcd.putstr("--------------------")
lcd.move_to(0,3)
lcd.putstr("[")
lcd.putchar(chr(2))
lcd.putstr("] exit")
time.sleep(1)
green.off()
except (InvalidPulseCount, InvalidChecksum):
green.off()
red.on()
lcd.clear()
lcd.move_to(0,1)
lcd.putstr("Trwa pobieranie")
lcd.move_to(0,2)
lcd.putstr("informacji poczekaj.")
time.sleep(1)
red.off()
if button_esc.value() == 0:
bluzzer.low()
utime.sleep_us(1000)
bluzzer.high()
time.sleep(0.3)
return
led = Pin("LED", Pin.OUT)
led.on()
display_menu(menu_page)
led_pins = [13,12,11]
leds = [Pin(pin, Pin.OUT) for pin in led_pins]
def led_test():
for led in leds:
led.on()
time.sleep(0.5)
led.off()
time.sleep(0.5)
for led in leds:
led.on()
time.sleep(0.5)
for led in leds:
led.off()
led_test()
while True:
if button_down.value() == 0:
menu_page += 1
bluzzer.low()
utime.sleep_us(1000)
bluzzer.high()
if menu_page > max_page:
menu_page = 0
display_menu(menu_page)
time.sleep(0.3)
if button_up.value() == 0:
menu_page -= 1
bluzzer.low()
utime.sleep_us(1000)
bluzzer.high()
if menu_page < 0:
menu_page = max_page
display_menu(menu_page)
time.sleep(0.3)
if button_enter.value() == 0:
if menu_page == 0:
bluzzer.low()
utime.sleep_us(1000)
bluzzer.high()
menu_page = 20
display_page_temp()
menu_page = 0
display_menu(menu_page)
time.sleep(0.3)
if button_esc.value() == 0:
if menu_page == 20:
bluzzer.low()
utime.sleep_us(1000)
bluzzer.high()
display_menu(0)
menu_page = 0
time.sleep(0.3)
time.sleep(0.05)