-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
118 lines (87 loc) · 2.36 KB
/
main.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
#!/usr/bin/env python3
# -*- coding: UTF-8 -*-
"""
Main script
Do your stuff here, this file is similar to the loop() function on Arduino
Example on how to manipulate all elements of page 0 with basic command calls
"""
# system packages
import time
# custom packages
from nextion import NexHardware
# define communication pins for Nextion display
tx_pin = 21
rx_pin = 22
# create Nextion hardware interface
nh = NexHardware(rx_pin=rx_pin, tx_pin=tx_pin)
# init nextion communication interface
nh.nexInit()
# modify text field "t0" showing "newtxt" by default
print('Set text field "t0" to "asdf"')
cmd = 't0.txt="asdf"'
nh.sendCommand(cmd)
print()
time.sleep(1)
# modify number field "n0" showing "0" by default
print('Set number field "n0" to "93"')
cmd = 'n0.val=93'
nh.sendCommand(cmd)
print()
time.sleep(1)
# modify float field "x0" showing "0.0" by default
print('Set float field "x0" to "20.1"')
cmd = 'x0.val=201' # last digit is value after "."
nh.sendCommand(cmd)
print()
time.sleep(1)
# modify button "b0" showing "newtxt" by default
print('Set button "b0" to "btn txt"')
cmd = 'b0.txt="btn txt"'
nh.sendCommand(cmd)
print()
time.sleep(1)
# modify progressbar "j0" showing "50%" by default
print('Set progressbar "j0" to "20"')
cmd = 'j0.val=20'
nh.sendCommand(cmd)
print()
time.sleep(1)
# modify slider "h0" showed in center position by default
print('Set slider "h0" to "80"')
cmd = 'h0.val=80'
nh.sendCommand(cmd)
print()
time.sleep(1)
# modify button "bt0" showing "newtxt" by default
print('Set button "bt0" to "btn txt"')
cmd = 'bt0.txt="btn txt"'
nh.sendCommand(cmd)
print()
time.sleep(1)
# modify checkbox "c0" being checked by default
print('Set checkbox "c0" to "unchecked"')
cmd = 'c0.val=0'
nh.sendCommand(cmd)
print()
time.sleep(1)
# modify radio button "r0" being enabled by default
print('Set radio butto "r0" to "disabled"')
cmd = 'r0.val=0'
nh.sendCommand(cmd)
print()
time.sleep(1)
# modify gauge "z0" pointing to the left by default
print('Set gauge "z0" to "135" (degree)')
cmd = 'z0.val=135'
nh.sendCommand(cmd)
print()
time.sleep(1)
# add several datapoints to waveform "s0"
print('Add several datapoints to waveform "s0"')
for x in range(0, 50):
cmd = 'add 14,0,{}'.format(x)
nh.sendCommand(cmd)
time.sleep(0.1)
print('Returning to REPL in 5 seconds')
# wait for 5 more seconds to safely finish the may still running threads
time.sleep(5)