Compare commits
No commits in common. "ea53f98cc811c5154d04c3a3947ec42e89c2de56" and "764a3aa040920a58c8d74446052546123e2c4c80" have entirely different histories.
ea53f98cc8
...
764a3aa040
71
main.py
71
main.py
@ -5,16 +5,22 @@ from PicoAirQuality import KitronikBME688, KitronikButton, KitronikDataLogger,
|
||||
KitronikBuzzer
|
||||
import time
|
||||
|
||||
#from datetime import datetime
|
||||
|
||||
logFileName = "atmosphere_log.txt"
|
||||
mindex=0
|
||||
morse = []
|
||||
#bme688 = KitronikBME688()
|
||||
oled = KitronikOLED()
|
||||
rtc = KitronikRTC()
|
||||
zipleds = KitronikZIPLEDs(3)
|
||||
# Python u arse hole sec = Integer()
|
||||
rtc.setDate(16, 7, 2022)
|
||||
rtc.setTime(12, 10, 0)
|
||||
rate = 50 # 20 wpm
|
||||
|
||||
#sec = 0
|
||||
rate = 60 # 20 wpm
|
||||
#bme688.setupGasSensor()
|
||||
#bme688.calcBaselines()
|
||||
sec = 0
|
||||
#f = open(logFileName, 'a')
|
||||
#f.write("# Data Logging: Date, Time, Temperature, Pressure, Humidity, AirQuality, CO2\n")
|
||||
|
||||
@ -23,22 +29,26 @@ buttons = KitronikButton()
|
||||
last_pv = 0
|
||||
last_tt = 0
|
||||
spurious = 0 # interrupts are often repeated for the low level
|
||||
button_state = 0 # on==1 off==0
|
||||
|
||||
# make this array size 20. A morse char of 5 dots|dashes
|
||||
# would take up 10 slots max.
|
||||
#
|
||||
|
||||
|
||||
def header():
|
||||
global rate, oled
|
||||
s = "Morse rate " + str(rate) + " mS"
|
||||
oled.displayText(s,1,0)
|
||||
class buttonEvent:
|
||||
#mstimestamp = 0
|
||||
#pinstate = 0
|
||||
def __init__(self, mststamp, pinst):
|
||||
buttonEvent.mstimestamp = mststamp
|
||||
buttonEvent.pinstate = pinst
|
||||
#def str(self):
|
||||
#return "mstimestamp:",str(mstimestamp), "pinst ",str(pinstate)
|
||||
|
||||
def ButtonA_f_IRQHandler(pin):
|
||||
global rate, oled
|
||||
rate += 10
|
||||
if rate > 100:
|
||||
rate = 40
|
||||
oled.clear()
|
||||
header()
|
||||
print (" IRQ button A" + str(rate))
|
||||
|
||||
#def ButtonB_r_IRQHandler(pin):
|
||||
# global buttonB
|
||||
# buttonB = 2*60
|
||||
# print("button B pressed", buttonB)
|
||||
|
||||
def ButtonB_f_IRQHandler(pin):
|
||||
global last_pv, last_tt, spurious, mindex
|
||||
@ -56,10 +66,9 @@ def ButtonB_f_IRQHandler(pin):
|
||||
if d < rate*3:
|
||||
print (" ")
|
||||
else:
|
||||
print (" ipi ")
|
||||
print (" interval ")
|
||||
mindex += 1;
|
||||
beeper.playTone(600)
|
||||
button_state = 1
|
||||
else:
|
||||
#print(" duration of press ", d)
|
||||
if d > rate*3:
|
||||
@ -69,14 +78,13 @@ def ButtonB_f_IRQHandler(pin):
|
||||
morse.append(".");
|
||||
print ("DIT")
|
||||
beeper.stopTone()
|
||||
button_state = 0
|
||||
last_pv = pv
|
||||
last_tt = tt
|
||||
|
||||
buttons.buttonB.irq(trigger=machine.Pin.IRQ_FALLING|machine.Pin.IRQ_RISING, \
|
||||
handler=ButtonB_f_IRQHandler)
|
||||
|
||||
buttons.buttonA.irq(trigger=machine.Pin.IRQ_RISING, handler=ButtonA_f_IRQHandler)
|
||||
# FALLING DOES NOT WORK AND IRQ_LOW_LEVEL not recognised
|
||||
buttons.buttonB.irq(trigger=machine.Pin.IRQ_FALLING|machine.Pin.IRQ_RISING, handler=ButtonB_f_IRQHandler)
|
||||
#buttons.buttonB.irq(trigger=machine.Pin.IRQ_RISING, handler=ButtonB_r_IRQHandler)
|
||||
|
||||
charbuf = []
|
||||
hpm=10
|
||||
@ -86,7 +94,7 @@ def printm(mchar):
|
||||
charbuf.append(mchar)
|
||||
chcnt = 0
|
||||
oled.clear()
|
||||
header()
|
||||
oled.displayText("Morse rxd",1,2)
|
||||
while len(charbuf) > (4*20):
|
||||
charbuf.pop(0) # get rid of old morse
|
||||
for i in range(2,6):
|
||||
@ -152,7 +160,7 @@ def decode_morse():
|
||||
if morse == dm_f:
|
||||
return ("F")
|
||||
if morse == dm_g:
|
||||
return ("G")
|
||||
print ("G")
|
||||
if morse == dm_h:
|
||||
return ("H")
|
||||
if morse == dm_i:
|
||||
@ -160,7 +168,7 @@ def decode_morse():
|
||||
if morse == dm_j:
|
||||
return ("J")
|
||||
if morse == dm_k:
|
||||
return ("K")
|
||||
print ("K")
|
||||
if morse == dm_l:
|
||||
return ("L")
|
||||
if morse == dm_m:
|
||||
@ -219,7 +227,6 @@ last_sp = 0
|
||||
def process_morse():
|
||||
global last_tt, morse, last_was_space, last_sp
|
||||
tt = time.ticks_ms()
|
||||
if (button_state == 0):
|
||||
if (tt - last_tt) > rate*6:
|
||||
# morse chacter complete
|
||||
if (len(morse) > 0):
|
||||
@ -228,17 +235,23 @@ def process_morse():
|
||||
morse = []
|
||||
last_was_space = 0
|
||||
last_sp = last_tt
|
||||
|
||||
#oled.clear()
|
||||
#oled.displayText(rtc.readDateString(), 1, 25)
|
||||
#oled.displayText(rtc.readTimeString(), 2, 33)
|
||||
#oled.displayText(str(mcount), 4, 33)
|
||||
#oled.show()
|
||||
if (tt - last_sp) > rate*22 : # and last_not_space == 0:
|
||||
if last_was_space == 0:
|
||||
printm(" ");
|
||||
last_was_space = 1 # dont keep repeating inter word spaces
|
||||
last_sp = last_tt
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
while True:
|
||||
# maybe a function can have a global ref, yeah maybe the main cont. another wanky aspect ogf pythion
|
||||
process_morse()
|
||||
|
||||
##process_morse2()
|
||||
#time.sleep(1.0)
|
||||
|
Loading…
Reference in New Issue
Block a user