-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.py
138 lines (107 loc) · 3.92 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
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
#!/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()
# ============================================================================
# ============================== Text examples ===============================
# 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)
# ============================================================================
# ============================= Number examples ==============================
# 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)
# ============================================================================
# ============================= Button examples ==============================
# 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 dual state button "bt0" showing "newtxt" by default
print('Set dual state button "bt0" to "dsb txt"')
cmd = 'bt0.txt="dsb txt"'
nh.sendCommand(cmd)
print()
time.sleep(1)
# ============================================================================
# =========================== Progressbar examples ===========================
# modify progressbar "j0" showing "50%" by default
print('Set progressbar "j0" to "20"')
cmd = 'j0.val=20'
nh.sendCommand(cmd)
print()
time.sleep(1)
# ============================================================================
# ============================= Slider examples ==============================
# 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)
# ============================================================================
# ============================ Checkbox examples =============================
# modify checkbox "c0" being checked by default
print('Set checkbox "c0" to "unchecked"')
cmd = 'c0.val=0'
nh.sendCommand(cmd)
print()
time.sleep(1)
# ============================================================================
# ============================== Radio examples ==============================
# 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)
# ============================================================================
# ============================== Gauge examples ==============================
# 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)
# ============================================================================
# ============================ Waveform examples =============================
# 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)
# ============================================================================
# ============================= End of example ===============================
print('Returning to REPL in 5 seconds')
# wait for 5 more seconds to safely finish the may still running threads
time.sleep(5)