Add files via upload
This commit is contained in:
170
senzor.py
Normal file
170
senzor.py
Normal file
@@ -0,0 +1,170 @@
|
||||
import machine
|
||||
from machine import Pin, ADC
|
||||
import DS18B20 as dsb
|
||||
import time
|
||||
import ne555 as ne
|
||||
import math
|
||||
import display
|
||||
import sys
|
||||
|
||||
def dane(vpr='Potrdi(d/n)->'):
|
||||
str=input(vpr)
|
||||
if str=='d':
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
try:
|
||||
display.init()
|
||||
from display import oled
|
||||
except:
|
||||
print('Napaka OLED!')
|
||||
if dane('Resetiram(d/n)->'):
|
||||
machine.reset()
|
||||
|
||||
|
||||
oled.text('OLED deluje!',0,0)
|
||||
oled.show()
|
||||
#Offline firmware za Vremensko postajo PTIT FE 2017
|
||||
try:
|
||||
svet=ADC(0) #svetloba
|
||||
pin12=tipka=Pin(12, Pin.IN) #tipka
|
||||
pin13=statusled=Pin(13, Pin.OUT) #status LED
|
||||
pin15=alertled=Pin(15, Pin.OUT ) #alert LED
|
||||
except:
|
||||
print('Napaka I/O!')
|
||||
if dane('Resetiram(d/n)->'):
|
||||
machine.reset()
|
||||
|
||||
oled.text('I/O postavljen!',0,10)
|
||||
oled.show()
|
||||
try:
|
||||
dsb.setup(0)
|
||||
except:
|
||||
print('Napaka Temp. senzorja!')
|
||||
if dane('Resetiram(d/n)->'):
|
||||
machine.reset()
|
||||
|
||||
oled.text('TS postavljen!',0,20)
|
||||
oled.show()
|
||||
time.sleep(1)
|
||||
|
||||
oled.fill(0)
|
||||
oled.text('<-------------->', 0, 15)
|
||||
oled.text('<NodeMCU Senzor>', 0, 25)
|
||||
oled.text('<-------------->', 0, 35)
|
||||
oled.text(' !Pozdravljeni! ', 0, 50)
|
||||
oled.show()
|
||||
time.sleep_ms(750)
|
||||
|
||||
oled.fill(0)
|
||||
oled.text('Tipka menja',0,0)
|
||||
oled.text('casovne razmike',0,10)
|
||||
oled.text('med meritvami',0,20)
|
||||
oled.text('0.25/0.5/1/2/10s',0,30)
|
||||
oled.text('7x tipka=izhod',0,40)
|
||||
oled.show()
|
||||
|
||||
time.sleep(4)
|
||||
oled.fill(0)
|
||||
oled.show()
|
||||
|
||||
statusled.value(1)
|
||||
alertled.value(0)
|
||||
|
||||
def konec(p):
|
||||
exit=1
|
||||
|
||||
|
||||
exit=0
|
||||
temp=0
|
||||
svetloba=0
|
||||
vlaga=0
|
||||
ms=15000
|
||||
active=0
|
||||
|
||||
def setsleep(x):
|
||||
global ms
|
||||
if ms==15000:
|
||||
ms=250
|
||||
elif ms==250:
|
||||
ms=500
|
||||
elif ms==500:
|
||||
ms=1000
|
||||
elif ms==1000:
|
||||
ms=2000
|
||||
elif ms==2000:
|
||||
ms=15000
|
||||
else:
|
||||
ms=15000
|
||||
|
||||
def carefulsleep():
|
||||
global ms, active, exit
|
||||
startticks=time.ticks_ms()
|
||||
firstticks=0
|
||||
lastticks=0
|
||||
while time.ticks_diff(time.ticks_ms(), startticks)<ms:
|
||||
update_screen()
|
||||
if tipka.value() == 0:
|
||||
if active==0 and firstticks==0:
|
||||
firstticks=time.ticks_ms()
|
||||
active=1
|
||||
lastticks=time.ticks_ms()
|
||||
if active==1 and ticks_diff(lastticks,firstticks)>3000:
|
||||
exit=1
|
||||
active=0
|
||||
firstticks=0
|
||||
lastticks=0
|
||||
if tipka.value()>0 and active==1 and ticks_diff(time.ticks_ms(),lastticks)>250:
|
||||
active=0
|
||||
lastticks=0
|
||||
firstticks=0
|
||||
setsleep()
|
||||
|
||||
def acq():
|
||||
global temp, svetloba, vlaga
|
||||
oled.text('BUSY...',70,55)
|
||||
alertled.value(1)
|
||||
oled.show()
|
||||
try:
|
||||
temp=dsb.read_temp()
|
||||
except:
|
||||
print('Napaka v branju temperature!')
|
||||
temp='NAPAKA'
|
||||
|
||||
try:
|
||||
svetloba=svet.read()
|
||||
except:
|
||||
print('Napaka v branju svetlobe!')
|
||||
svetloba='NAPAKA'
|
||||
|
||||
try:
|
||||
vlaga=ne.main()
|
||||
except:
|
||||
print('Napaka v branju vlage!')
|
||||
vlaga='NAPAKA'
|
||||
|
||||
alertled.value(0)
|
||||
|
||||
def update_screen():
|
||||
oled.fill(0)
|
||||
oled.text('T: ' + str(temp) + 'C',15,10)
|
||||
oled.text('S: ' + str(svetloba) + ' enot',15,20)
|
||||
oled.text('RH: ' + str(vlaga) +' Hz', 15, 30)
|
||||
oled.text('NodeMCU Senzor',0,0)
|
||||
oled.text('Uptime: ' + str(time.time()) + 's',5,45)
|
||||
oled.text('S: ' + str(ms) + 's',0,55)
|
||||
oled.show()
|
||||
|
||||
while exit<1:
|
||||
acq()
|
||||
update_screen()
|
||||
carefulsleep()
|
||||
|
||||
oled.fill(0)
|
||||
oled.text('<-------------->', 0, 15)
|
||||
oled.text('<NodeMCU Senzor>', 0, 25)
|
||||
oled.text('<-------------->', 0, 35)
|
||||
oled.text(' !Nasvidenje! ', 0, 50)
|
||||
oled.show()
|
||||
time.sleep(1.5)
|
||||
oled.poweroff()
|
||||
Reference in New Issue
Block a user