-
Notifications
You must be signed in to change notification settings - Fork 0
/
pyqt5.py
69 lines (52 loc) · 1.7 KB
/
pyqt5.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
import sys
import time
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from PyQt5.QtWidgets import *
import spi
GLOBAL_Zero1=0
GLOBAL_Zero2=0
class MyTimer(QWidget):
def __init__(self, parent = None):
super(MyTimer, self).__init__(parent)
self.resize(400, 400)
self.setWindowTitle("QTimerDemo")
self.lcd1 = QLCDNumber()
self.lcd1.setDigitCount(6)
self.lcd1.setMode(QLCDNumber.Dec)
self.lcd1.setSegmentStyle(QLCDNumber.Flat)
self.lcd1.display(0)
self.lcd2 = QLCDNumber()
self.lcd2.setDigitCount(6)
self.lcd2.setMode(QLCDNumber.Dec)
self.lcd2.setSegmentStyle(QLCDNumber.Flat)
self.lcd2.display(0)
layout = QVBoxLayout()
layout.addWidget(self.lcd1)
layout.addWidget(self.lcd2)
self.setLayout(layout)
self.timer = QTimer()
self.timer.setInterval(200)
self.timer.start()
self.timer.timeout.connect(self.onTimerOut)
self.rw = spi.AD770X()
self.ZeroOut()
def ZeroOut(self):
time.sleep(1)
GLOBAL_Zero1 = self.rw.readADResultRaw(spi.CHN_AIN1)
time.sleep(0.1)
GLOBAL_Zero2 = self.rw.readADResultRaw(spi.CHN_AIN2)
def onTimerOut(self):
a = self.rw.readADResultRaw(spi.CHN_AIN1)
a-=GLOBAL_Zero1
a/=134.21
time.sleep(0.1)
b = self.rw.readADResultRaw(spi.CHN_AIN2)
b-=GLOBAL_Zero2
b/=134.21
self.lcd1.display("%.1f"%a)
self.lcd2.display("%.1f"%b)
app = QApplication(sys.argv)
t = MyTimer()
t.show()
sys.exit(app.exec_())