Advertisement
Vasilena

GUIDiplomna

May 25th, 2023
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 22.64 KB | None | 0 0
  1. import tkinter as tk
  2. from tkinter import *
  3. from tkinter import ttk
  4. from tkinter import messagebox
  5. import tkinter.messagebox
  6. from pump_two_on import PumpTwoOn
  7. from pump_two_off import PumpTwoOff
  8. from pump_one_on import PumpOneOn
  9. from pump_one_off import PumpOneOff
  10. from exit import Exit
  11. import RPi.GPIO as GPIO
  12. import math
  13. import time
  14.  
  15. GPIO.setwarnings(False)
  16. GPIO.setmode(GPIO.BOARD)
  17.  
  18. GPIO.setup(36, GPIO.IN) # pump one
  19. # GPIO.setup(40, GPIO.IN) # pumo two
  20. # GPIO.setup(38, GPIO.IN) # pumo three
  21.  
  22. # tank one gpio senzors setup
  23. GPIO.setup(18, GPIO.IN)
  24. GPIO.setup(22, GPIO.IN)
  25. GPIO.setup(21, GPIO.IN)
  26. GPIO.setup(23, GPIO.IN)
  27. GPIO.setup(24, GPIO.IN)
  28.  
  29. # tank two gpio sen+zors setup
  30. GPIO.setup(11, GPIO.IN)
  31. GPIO.setup(12, GPIO.IN)
  32. GPIO.setup(13, GPIO.IN)
  33. GPIO.setup(15, GPIO.IN)
  34. GPIO.setup(16, GPIO.IN)
  35.  
  36. # tank three gpio senzors setup
  37. GPIO.setup(29, GPIO.IN)
  38. GPIO.setup(31, GPIO.IN)
  39. GPIO.setup(33, GPIO.IN)
  40. GPIO.setup(35, GPIO.IN)
  41. GPIO.setup(37, GPIO.IN)
  42.  
  43. GPIO.setup(29, GPIO.IN)
  44. GPIO.setup(31, GPIO.IN)
  45. GPIO.setup(33, GPIO.IN)
  46. GPIO.setup(35, GPIO.IN)
  47. GPIO.setup(37, GPIO.IN)
  48.  
  49. GPIO.setup(36, GPIO.OUT)
  50. GPIO.setup(38, GPIO.OUT)
  51. GPIO.setup(40, GPIO.OUT)
  52.  
  53. class Window:
  54.  
  55. def __init__(self, root):
  56. # --------------------------------TK-------------------------------
  57. # root setup
  58. self.window = root
  59. self.background_color = '#999da0'
  60. self.window.attributes('-fullscreen', True)
  61. self.window.title("Control Panel")
  62. self.window.configure(background='#999da0')
  63.  
  64. self.animating_one = False
  65. self.animating_two = False
  66. self.animating_three = False
  67.  
  68. # root geometry
  69. self.screen_width = self.window.winfo_screenwidth() # 1920
  70. self.screen_height = self.window.winfo_screenheight() # 1080
  71.  
  72. # manual mode
  73. self.manual = Label(root, text="РЪЧНО УПРАВЛЕНИЕ", font=('Arial', 30), bg=self.background_color, fg="black")
  74. self.manual.place(x=(self.screen_width / 3) * 2.15, y=self.screen_height / 20)
  75.  
  76. self.pumpOne = Label(root, text="ПОМПА 1", font=('Arial', 20), bg=self.background_color, fg="black")
  77. self.pumpOne.place(x=(self.screen_width / 3) * 2.17, y=self.screen_height / 8)
  78.  
  79. self.pumpTwo = Label(root, text="ПОМПА 2", font=('Arial', 20), bg=self.background_color, fg="black")
  80. self.pumpTwo.place(x=(self.screen_width / 3) * 2.6, y=self.screen_height / 8)
  81.  
  82. # buttons
  83. self.pump_one_on_btn = Button(root, text="ВКЛЮЧИ", font=("Arial", 15, "bold"), command=self.pump_one_on_func, bg="#198FF5", fg="white")
  84. self.pump_one_on_btn.place(x=(self.screen_width / 3) * 2.18, y=self.screen_height / 5.8)
  85. if(GPIO.input(36) == 1):
  86. print("yes")
  87. self.pump_one_off_btn = Button(root, text="ИЗКЛЮЧИ", font=("Arial", 15, "bold"), command=self.pump_one_off_func, bg="#696969", fg="white")
  88. self.pump_one_off_btn.place(x=(self.screen_width / 3) * 2.16, y=self.screen_height / 4.5)
  89.  
  90. # separator
  91. self.separator_frame = Frame(root, bg="black", width=2, height=150)
  92. self.separator_frame.place(x=1590, y=137)
  93.  
  94. self.pump_two_on_btn = Button(root, text="ВКЛЮЧИ", font=("Arial", 15, "bold"), command=self.pump_two_on_func, bg="#198FF5", fg="white")
  95. self.pump_two_on_btn.place(x=(self.screen_width / 3) * 2.6, y=self.screen_height / 5.8)
  96.  
  97. self.pump_two_off_btn = Button(root, text="ИЗКЛЮЧИ", font=("Arial", 15, "bold"), command=self.pump_two_off_func, bg="#696969", fg="white")
  98. self.pump_two_off_btn.place(x=(self.screen_width / 3) * 2.6, y=self.screen_height / 4.5)
  99.  
  100. # draning
  101. self.manual = Label(root, text="ГЛАВЕН РЕЗЕРВОАР", font=('Arial', 30), bg=self.background_color, fg="black")
  102. self.manual.place(x=(self.screen_width / 3) * 2.15, y=self.screen_height / 3.3)
  103.  
  104. self.pump_two_off_btn = Button(root, text="ИЗТОЧВАНЕ", font=("Arial", 15, "bold"), command=self.drain_func, bg="#F06B5D", fg="white")
  105. self.pump_two_off_btn.place(x=(self.screen_width / 3) * 2.35, y=self.screen_height / 2.7)
  106.  
  107. # separator
  108. self.separator_frame = Frame(root, bg="black", width=470, height=2)
  109. self.separator_frame.place(x=1360, y=480)
  110.  
  111. # exit program button
  112. self.exit_btn = Button(root, text="X", height=1, width=2, font=("Arial", 15, "bold"),
  113. command=self.Exit_btn_func, bg="#EF4324", fg="white")
  114. self.exit_btn.place(x=self.screen_width - 55, y=self.screen_height - (self.screen_height - 5))
  115.  
  116. # automatic mode
  117. self.automatic = Label(root, text="АВТОМАТИЧНО УПРАВЛЕНИЕ", font=('Arial', 25), bg=self.background_color,
  118. fg="black")
  119. self.automatic.place(x=(self.screen_width / 3) * 2.1, y=self.screen_height / 2.1)
  120.  
  121. self.tankOne = Label(root, text="РЕЗЕРВОАР 1", font=('Arial', 20), bg=self.background_color, fg="black")
  122. self.tankOne.place(x=(self.screen_width / 3) * 2.13, y=self.screen_height / 1.9)
  123.  
  124. # separator
  125. self.separator_frame = Frame(root, bg="black", width=2, height=120)
  126. self.separator_frame.place(x=1590, y=570)
  127.  
  128. self.tankTwo = Label(root, text="РЕЗЕРВОАР 2", font=('Arial', 20), bg=self.background_color, fg="black")
  129. self.tankTwo.place(x=(self.screen_width / 3) * 2.55, y=self.screen_height / 1.9)
  130.  
  131. # dropdown menus
  132. self.tank1_label = tk.Label(root, text="избери:", bg=self.background_color, font=('Arial', 18))
  133. self.tank1_label.place(x=(self.screen_width / 3) * 2.17, y=self.screen_height / 1.7)
  134. self.tank1_value_inside = tk.StringVar(value="0%")
  135. self.tank1_options = ["0%", "20%", "40%", "60%", "80%", "100%"]
  136. self.tank1_dropdown = tk.OptionMenu(root, self.tank1_value_inside, *self.tank1_options)
  137. self.tank1_dropdown.place(x=(self.screen_width / 3) * 2.32, y=self.screen_height / 1.7)
  138.  
  139. # dropdown menus
  140. self.tank2_label = tk.Label(root, text="избери:", bg=self.background_color, font=('Arial', 18))
  141. self.tank2_label.place(x=(self.screen_width / 3) * 2.55, y=self.screen_height / 1.7)
  142. self.tank2_value_inside = tk.StringVar(value="0%")
  143. self.tank2_options = ["0%", "20%", "40%", "60%", "80%", "100%"]
  144. self.tank2_dropdown = tk.OptionMenu(root, self.tank2_value_inside, *self.tank2_options)
  145. self.tank2_dropdown.place(x=(self.screen_width / 3) * 2.70, y=self.screen_height / 1.7)
  146.  
  147. # sequence option
  148. self.automatic = Label(root, text="ИЗБЕРИ ПОСЛЕДОВАТЕЛНОСТ", font=('Arial', 25), bg=self.background_color,
  149. fg="black")
  150. self.automatic.place(x=(self.screen_width / 3) * 2.1, y=self.screen_height / 1.5)
  151.  
  152. # create a label and two radio buttons for the first sequence option
  153. self.sequence1_label = tk.Label(root, text='ЕДНО', bg=self.background_color, font=('Arial', 20))
  154. self.sequence1_label.place(x=(self.screen_width / 3) * 2.3, y=self.screen_height / 1.4)
  155.  
  156. self.sequence1_var = tk.StringVar(root)
  157. self.sequence1_var.set('Резервоар 1')
  158.  
  159. self.sequence1_rb1 = tk.Radiobutton(root, text='Резервоар 1 ', bg=self.background_color, font=('Arial', 15),
  160. variable=self.sequence1_var, value='Резервоар 1')
  161. self.sequence1_rb1.place(x=(self.screen_width / 3) * 2.15, y=self.screen_height / 1.31)
  162. self.sequence1_rb2 = tk.Radiobutton(root, text='Резервоар 2 ', bg=self.background_color, font=('Arial', 15),
  163. variable=self.sequence1_var, value='Резервоар 2')
  164. self.sequence1_rb2.place(x=(self.screen_width / 3) * 2.15, y=self.screen_height / 1.24)
  165.  
  166. # separator
  167. self.separator_frame = Frame(root, bg="black", width=2, height=122)
  168. self.separator_frame.place(x=1590, y=780)
  169.  
  170. # create a label and two radio buttons for the second sequence option
  171. self.sequence2_label = tk.Label(root, text='ДВЕ', font=('Arial', 20), bg=self.background_color, fg="black")
  172. self.sequence2_label.place(x=(self.screen_width / 3) * 2.55, y=self.screen_height / 1.4)
  173.  
  174. self.sequence2_var = tk.StringVar(root)
  175. self.sequence2_var.set('Резервоар 2')
  176.  
  177. self.sequence2_rb1 = tk.Radiobutton(root, text='Резервоар 1 ', bg=self.background_color, font=('Arial', 15),
  178. variable=self.sequence2_var, value='Резервоар 1')
  179. self.sequence2_rb1.place(x=(self.screen_width / 3) * 2.57, y=self.screen_height / 1.31)
  180. self.sequence2_rb2 = tk.Radiobutton(root, text='Резервоар 2 ', bg=self.background_color, font=('Arial', 15),
  181. variable=self.sequence2_var, value='Резервоар 2')
  182. self.sequence2_rb2.place(x=(self.screen_width / 3) * 2.57, y=self.screen_height / 1.24)
  183.  
  184. # start and stop button
  185.  
  186. self.start = Button(root, text="СТАРТИРАЙ", font=('Arial', 25), bg="#41be87", fg="white",
  187. command=self.overflow_btn_on)
  188. self.start.place(x=(self.screen_width / 3) * 2.13, y=self.screen_height / 1.15)
  189.  
  190. self.stop = Button(root, text="ИЗТОЧВАНЕ", font=('Arial', 25), bg="#e2651d", fg="white",
  191. command=self.drain_func)
  192. self.stop.place(x=(self.screen_width / 3) * 2.5, y=self.screen_height / 1.15)
  193.  
  194. # --------------------------------Canvas-------------------------------
  195. # canvas setup
  196. self.canvas = Canvas(root, width=(self.screen_width / 3) * 2, height=self.screen_height,
  197. bg=self.background_color)
  198. self.canvas.pack()
  199. self.canvas.place(bordermode=OUTSIDE)
  200.  
  201. # heading
  202. self.canvas.create_text(self.screen_width / 3, self.screen_height / 18, text='К О Н Т Р О Л Е Н П А Н Е Л',
  203. fill='black', font='Arial 25')
  204.  
  205. # create scale tank One
  206. self.canvas.create_line(65, 140, 65, 520, width=2)
  207. for i in range(6):
  208. self.p1 = 100 - i * 20
  209. self.y1 = 140
  210. self.y1 = self.y1 + i * 76
  211. self.canvas.create_text(25, self.y1, text=self.p1, font=("Arial", 13, "bold"))
  212. self.canvas.create_text(45, self.y1, text="%", font=("Arial", 13, "bold"))
  213. self.canvas.create_line(65, self.y1, 75, self.y1, width=2)
  214.  
  215. # create scale tank Two
  216. self.canvas.create_line(65, 600, 65, 980, width=2)
  217. for i in range(6):
  218. self.p = 100 - i * 20
  219. self.y = 600
  220. self.y = self.y + i * 76
  221. self.canvas.create_text(25, self.y, text=self.p, font=("Arial", 13, "bold"))
  222. self.canvas.create_text(45, self.y, text=" %", font=("Arial", 13, "bold"))
  223. self.canvas.create_line(65, self.y, 75, self.y, width=2)
  224.  
  225. # create scale tank Three
  226. self.canvas.create_line(1185, 200, 1185, 900, width=3)
  227. for i in range(6):
  228. self.p = 100 - i * 20
  229. self.y2 = 200
  230. self.y2 = self.y2 + i * 140
  231. self.canvas.create_text(1205, self.y2, text=self.p, font=("Arial", 15, "bold"))
  232. self.canvas.create_text(1230, self.y2, text=" %", font=("Arial", 15, "bold"))
  233. self.canvas.create_line(1160, self.y2, 1186, self.y2, width=3)
  234.  
  235. # tank One (T1)
  236. self.canvas.create_rectangle(80, 140, 360, 520, fill='#d9dddc')
  237. # tank One Water
  238. self.waterOne = self.canvas.create_rectangle(80, 140, 360, 520, fill='blue')
  239.  
  240. self.tank1_label_canvas = tk.Label(root, text="Резервоар 1", bg=self.background_color, font=('Arial', 18))
  241. self.tank1_label_canvas.place(x=80, y=100)
  242.  
  243. # tank Two (T2)
  244. self.canvas.create_rectangle(80, 600, 360, 980, fill='#d9dddc')
  245. # tank Two Water
  246. self.waterTwo = self.canvas.create_rectangle(80, 600, 360, 980, fill='blue')
  247.  
  248. self.tank2_label_canvas = tk.Label(root, text="Резервоар 2", bg=self.background_color, font=('Arial', 18))
  249. self.tank2_label_canvas.place(x=80, y=560)
  250.  
  251. # tank Three (T3)
  252. self.canvas.create_rectangle(750, 200, 1150, 900, fill='#d9dddc')
  253. # tank Three Water
  254. self.waterThree = self.canvas.create_rectangle(750, 200, 1150, 900, fill='blue')
  255.  
  256. self.tank3_label_canvas = tk.Label(root, text="Резервоар 3", bg=self.background_color, font=('Arial', 20))
  257. self.tank3_label_canvas.place(x=995, y=155)
  258.  
  259. # pump One (p40)
  260. self.ovalOne = self.canvas.create_oval(385, 380, 515, 510, fill='#6b6b6b', width=15)
  261. self.Pump1line1 = self.canvas.create_line(400, 450, 500, 450, width=3)
  262. self.Pump1line2 = self.canvas.create_line(450, 400, 450, 500, width=3)
  263.  
  264. self.pump1_label_canvas = tk.Label(root, text="Помпа 1", bg=self.background_color, font=('Arial', 18))
  265. self.pump1_label_canvas.place(x=405, y=340)
  266.  
  267. # pump Two (p40)
  268. self.ovalTwo = self.canvas.create_oval(385, 835, 515, 965, fill='#6b6b6b', width=15)
  269. self.Pump2line1 = self.canvas.create_line(400, 900, 500, 900, width=3)
  270. self.Pump2line2 = self.canvas.create_line(450, 850, 450, 950, width=3)
  271.  
  272. self.pump2_label_canvas = tk.Label(root, text="Помпа 2", bg=self.background_color, font=('Arial', 18))
  273. self.pump2_label_canvas.place(x=405, y=790)
  274.  
  275. self.labelDrain = self.canvas.create_text(1000, 950, text="", fill="black", font=('Arial', 20))
  276.  
  277. def Exit_btn_func(self):
  278. self.Exit_btn = Exit().exit()
  279. if self.Exit_btn > 0:
  280. self.window.destroy()
  281. return
  282.  
  283. def check_condition_water_tank_one(self):
  284. if self.sum == 1:
  285. return 444
  286. elif self.sum == 2:
  287. return 368
  288. elif self.sum == 3:
  289. return 292
  290. elif self.sum == 4:
  291. return 216
  292. elif self.sum == 5:
  293. return 140
  294. else:
  295. return 520
  296.  
  297.  
  298. def check_condition_water_tank_two(self):
  299. if self.sum == 1:
  300. return 904
  301. elif self.sum == 2:
  302. return 828
  303. elif self.sum == 3:
  304. return 752
  305. elif self.sum == 4:
  306. return 676
  307. elif self.sum == 5:
  308. return 600
  309. else:
  310. return 980
  311.  
  312. def check_condition_water_tank_three(self):
  313. if self.sum == 1:
  314. return 760
  315. elif self.sum == 2:
  316. return 620
  317. elif self.sum == 3:
  318. return 480
  319. elif self.sum == 4:
  320. return 340
  321. elif self.sum == 5:
  322. return 200
  323. else:
  324. return 900
  325.  
  326. def update_water_tank_one(self):
  327. self.sum = GPIO.input(18) + GPIO.input(22) + GPIO.input(21) + GPIO.input(23) + GPIO.input(24)
  328. self.y1 = self.check_condition_water_tank_one()
  329. self.canvas.coords(self.waterOne, 80, self.y1, 360, 520)
  330. self.window.after(300, self.update_water_tank_one)
  331.  
  332. def update_water_tank_two(self):
  333. self.sum = GPIO.input(15) + GPIO.input(13) + GPIO.input(12) + GPIO.input(16) + GPIO.input(11)
  334. self.y1 = self.check_condition_water_tank_two()
  335. self.canvas.coords(self.waterTwo, 80, self.y1, 360, 980)
  336. self.window.after(300, self.update_water_tank_two)
  337.  
  338. def update_water_tank_three(self):
  339. self.sum = GPIO.input(29) + GPIO.input(31) + GPIO.input(33) + GPIO.input(35) + GPIO.input(37)
  340. self.y1 = self.check_condition_water_tank_three()
  341. self.canvas.coords(self.waterThree, 750, self.y1, 1150, 900)
  342. self.window.after(300, self.update_water_tank_three)
  343.  
  344. def animate_one(self, angle):
  345. x1, y1, x2, y2 = self.canvas.coords(self.Pump1line1)
  346. cx, cy = (x1 + x2) / 2, (y1 + y2) / 2
  347. new_x1 = cx + (x1 - cx) * math.cos(angle) - (y1 - cy) * math.sin(angle)
  348. new_y1 = cy + (x1 - cx) * math.sin(angle) + (y1 - cy) * math.cos(angle)
  349. new_x2 = cx + (x2 - cx) * math.cos(angle) - (y2 - cy) * math.sin(angle)
  350. new_y2 = cy + (x2 - cx) * math.sin(angle) + (y2 - cy) * math.cos(angle)
  351. self.canvas.coords(self.Pump1line1, new_x1, new_y1, new_x2, new_y2)
  352.  
  353. x1, y1, x2, y2 = self.canvas.coords(self.Pump1line2)
  354. cx, cy = (x1 + x2) / 2, (y1 + y2) / 2
  355. new_x1 = cx + (x1 - cx) * math.cos(angle) - (y1 - cy) * math.sin(angle)
  356. new_y1 = cy + (x1 - cx) * math.sin(angle) + (y1 - cy) * math.cos(angle)
  357. new_x2 = cx + (x2 - cx) * math.cos(angle) - (y2 - cy) * math.sin(angle)
  358. new_y2 = cy + (x2 - cx) * math.sin(angle) + (y2 - cy) * math.cos(angle)
  359. self.canvas.coords(self.Pump1line2, new_x1, new_y1, new_x2, new_y2)
  360.  
  361. if self.animating_one:
  362. self.canvas.after(10, self.animate_one, angle + 0.1)
  363.  
  364. def animate_two(self, angle):
  365. x1, y1, x2, y2 = self.canvas.coords(self.Pump2line1)
  366. cx, cy = (x1 + x2) / 2, (y1 + y2) / 2
  367. new_x1 = cx + (x1 - cx) * math.cos(angle) - (y1 - cy) * math.sin(angle)
  368. new_y1 = cy + (x1 - cx) * math.sin(angle) + (y1 - cy) * math.cos(angle)
  369. new_x2 = cx + (x2 - cx) * math.cos(angle) - (y2 - cy) * math.sin(angle)
  370. new_y2 = cy + (x2 - cx) * math.sin(angle) + (y2 - cy) * math.cos(angle)
  371. self.canvas.coords(self.Pump2line1, new_x1, new_y1, new_x2, new_y2)
  372.  
  373. x1, y1, x2, y2 = self.canvas.coords(self.Pump2line2)
  374. cx, cy = (x1 + x2) / 2, (y1 + y2) / 2
  375. new_x1 = cx + (x1 - cx) * math.cos(angle) - (y1 - cy) * math.sin(angle)
  376. new_y1 = cy + (x1 - cx) * math.sin(angle) + (y1 - cy) * math.cos(angle)
  377. new_x2 = cx + (x2 - cx) * math.cos(angle) - (y2 - cy) * math.sin(angle)
  378. new_y2 = cy + (x2 - cx) * math.sin(angle) + (y2 - cy) * math.cos(angle)
  379. self.canvas.coords(self.Pump2line2, new_x1, new_y1, new_x2, new_y2)
  380.  
  381. if self.animating_two:
  382. self.canvas.after(10, self.animate_two, angle + 0.1)
  383.  
  384. def get_tank_num(self, option):
  385. switcher = {
  386. "0%": 0,
  387. "20%": 1,
  388. "40%": 2,
  389. "60%": 3,
  390. "80%": 4,
  391. "100%": 5
  392. }
  393. return switcher.get(option)
  394.  
  395. def pump_one_on_func(self):
  396. PumpOneOn()
  397. if not self.animating_one:
  398. self.animating_one = True
  399. self.animate_one(0)
  400.  
  401. def pump_one_off_func(self):
  402. PumpOneOff()
  403. self.animating_one = False
  404.  
  405. def pump_two_on_func(self):
  406. PumpTwoOn()
  407. if not self.animating_two:
  408. self.animating_two = True
  409. self.animate_two(0)
  410.  
  411. def pump_two_off_func(self):
  412. PumpTwoOff()
  413. self.animating_two = False
  414.  
  415. def drain_func(self):
  416. print("drain start")
  417. self.canvas.itemconfig(self.labelDrain, text="Източване...Моля, изчакайте!")
  418. self.canvas.update()
  419.  
  420. self.sum3 = GPIO.input(29) + GPIO.input(31) + GPIO.input(33) + GPIO.input(35) + GPIO.input(37)
  421. print(self.sum3)
  422.  
  423. while self.sum3 > 0:
  424. GPIO.output(40, GPIO.HIGH)
  425. self.sum3 = GPIO.input(29) + GPIO.input(31) + GPIO.input(33) + GPIO.input(35) + GPIO.input(37)
  426. time.sleep(6.5)
  427. print(self.sum3)
  428.  
  429. GPIO.output(40, GPIO.LOW)
  430.  
  431. self.canvas.itemconfig(self.labelDrain, text="Източването е завършено!")
  432. self.canvas.after(3000, self.restore_label_text)
  433. print("drain end")
  434.  
  435. def restore_label_text(self):
  436. self.canvas.itemconfig(self.labelDrain, text="")
  437.  
  438. def overflow_btn_on(self):
  439. if int(self.tank2_value_inside.get()[:-1]) + int(self.tank1_value_inside.get()[:-1]) != 100 \
  440. or self.sequence2_var.get() == self.sequence1_var.get():
  441. messagebox.showwarning("Предупреждение", "Въведените данни не са равни на 100%!")
  442. else:
  443. first = self.sequence1_var.get()
  444. self.num = self.get_tank_num(self.tank1_value_inside.get())
  445. self.num2 = self.get_tank_num(self.tank2_value_inside.get())
  446.  
  447. if first == "Резервоар 1":
  448. self.sum = GPIO.input(29) + GPIO.input(31) + GPIO.input(33) + GPIO.input(35) + GPIO.input(37)
  449.  
  450. while self.sum < self.num:
  451. GPIO.output(36, GPIO.HIGH)
  452. self.sum = GPIO.input(29) + GPIO.input(31) + GPIO.input(33) + GPIO.input(35) + GPIO.input(37)
  453. print(self.sum)
  454. time.sleep(2)
  455. GPIO.output(36, GPIO.LOW)
  456.  
  457. self.sum2 = GPIO.input(29) + GPIO.input(31) + GPIO.input(33) + GPIO.input(35) + GPIO.input(37)
  458.  
  459. while self.sum2 < self.num2:
  460. GPIO.output(38, GPIO.HIGH)
  461. self.sum2 = GPIO.input(29) + GPIO.input(31) + GPIO.input(33) + GPIO.input(35) + GPIO.input(37)
  462. print(self.sum2)
  463. time.sleep(2)
  464. GPIO.output(38, GPIO.LOW)
  465.  
  466. elif first == "Резервоар 2":
  467. self.sum = GPIO.input(29) + GPIO.input(31) + GPIO.input(33) + GPIO.input(35) + GPIO.input(37)
  468.  
  469. while self.sum < self.num2:
  470. GPIO.output(38, GPIO.HIGH)
  471. self.sum = GPIO.input(29) + GPIO.input(31) + GPIO.input(33) + GPIO.input(35) + GPIO.input(37)
  472. print(self.sum)
  473. time.sleep(2)
  474. GPIO.output(38, GPIO.LOW)
  475.  
  476. self.sum2 = GPIO.input(29) + GPIO.input(31) + GPIO.input(33) + GPIO.input(35) + GPIO.input(37)
  477.  
  478. while self.sum2 < self.num:
  479. GPIO.output(36, GPIO.HIGH)
  480. self.sum2 = GPIO.input(29) + GPIO.input(31) + GPIO.input(33) + GPIO.input(35) + GPIO.input(37)
  481. time.sleep(2)
  482. GPIO.output(36, GPIO.LOW)
  483.  
  484. def overflow_btn_off(self):
  485. ...
  486.  
  487.  
  488. if __name__ == "__main__":
  489. root = tk.Tk()
  490. obj = Window(root)
  491. obj.update_water_tank_one()
  492. obj.update_water_tank_two()
  493. obj.update_water_tank_three()
  494. root.mainloop()
  495.  
  496.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement