Skip to content

Commit ed0a46d

Browse files
authored
Add files via upload
1 parent 79ec1a1 commit ed0a46d

File tree

5 files changed

+290
-0
lines changed

5 files changed

+290
-0
lines changed
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
// https://www.youtube.com/c/MagnoEfren
2+
// Señal analógica en PorgressBar Circular en PySide2 / PyQt5
3+
4+
float lectura;
5+
float voltaje;
6+
7+
void setup() {
8+
9+
Serial.begin(9600);
10+
pinMode(A0,INPUT);
11+
}
12+
13+
void loop() {
14+
lectura = analogRead(A0);
15+
voltaje = ((lectura/1023)*5.5);
16+
17+
Serial.println(voltaje);
18+
19+
delay(200);
20+
}
Lines changed: 59 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,59 @@
1+
# ProgressBar Circular Arduino y PySide2
2+
# @autor: Magno Efren
3+
# Youtube: https://www.youtube.com/c/MagnoEfren
4+
5+
6+
from PySide2.QtCore import Signal, QObject # pyqtSignal para pyqt5
7+
import serial, serial.tools.list_ports
8+
from threading import Thread, Event
9+
10+
class Comunicacion(QObject):
11+
datos_recibidos = Signal(str)
12+
13+
def __init__(self):
14+
super().__init__()
15+
self.arduino = serial.Serial()
16+
self.arduino.timeout = 0.5
17+
18+
self.baudrates = ['1200', '2400', '4800', '9600', '19200', '38400', '115200']
19+
self.puertos = []
20+
21+
self.hilo = None
22+
self.alive = Event() #indica que esta activo
23+
24+
def puertos_disponibles(self):
25+
self.puertos = [port.device for port in serial.tools.list_ports.comports()]
26+
27+
def conexion_serial(self):
28+
try:
29+
self.arduino.open()
30+
except:
31+
pass
32+
33+
if (self.arduino.is_open): # iniciamos el hilo cuando puerto esta abierto
34+
self.iniciar_hilo()
35+
36+
37+
def desconectar(self):
38+
self.stop_hilo()
39+
self.arduino.close()
40+
41+
def leer_datos(self):
42+
while(self.alive.isSet() and self.arduino.is_open):
43+
44+
data = self.arduino.readline().decode("utf-8").strip()
45+
if(len(data)>1):
46+
self.datos_recibidos.emit(data)
47+
48+
49+
def iniciar_hilo(self):
50+
self.hilo = Thread(target= self.leer_datos)
51+
self.hilo.setDaemon(1)
52+
self.alive.set()
53+
self.hilo.start()
54+
55+
def stop_hilo(self):
56+
if(self.hilo is not None):
57+
self.alive.clear()
58+
self.hilo.join()
59+
self.hilo = None
Loading
Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
# ProgressBar Circular Arduino y PySide2
2+
# @autor: Magno Efren
3+
# Youtube: https://www.youtube.com/c/MagnoEfren
4+
5+
6+
import sys
7+
from ui_progressBarCircular import *
8+
from comunicacion_serial import Comunicacion
9+
from PyQt5.QtCore import QTimer
10+
11+
12+
class MiApp(QtWidgets.QMainWindow):
13+
def __init__(self,*args, **kwargs):
14+
super().__init__()
15+
self.ui = Ui_MainWindow()
16+
self.ui.setupUi(self)
17+
18+
self.serial = Comunicacion()
19+
self.puertos_disponible()
20+
self.nivel = 0.0
21+
22+
self.serial.datos_recibidos.connect(self.datos_arduino)
23+
self.ui.velocidad.addItems(self.serial.baudrates)
24+
self.ui.velocidad.setCurrentText("9600")
25+
26+
self.ui.conectar.clicked.connect(self.conectar)
27+
self.ui.actualizar.clicked.connect(self.mostrar_barra)
28+
self.ui.desconectar.clicked.connect(self.desconectar)
29+
30+
31+
def datos_arduino(self, data):
32+
self.nivel = float(data)
33+
34+
def conectar(self):
35+
port = self.ui.puertos.currentText()
36+
baud = self.ui.velocidad.currentText()
37+
self.serial.arduino.port = port
38+
self.serial.arduino.baudrate = baud
39+
self.serial.conexion_serial()
40+
41+
42+
43+
def desconectar(self):
44+
self.serial.desconectar()
45+
46+
def mostrar_barra(self):
47+
self.progressbar()
48+
49+
QTimer.singleShot(20, self.mostrar_barra)
50+
51+
def puertos_disponible(self):
52+
self.serial.puertos_disponibles()
53+
self.ui.puertos.clear()
54+
self.ui.puertos.addItems(self.serial.puertos)
55+
56+
def progressbar(self):
57+
estilo = """ QFrame{
58+
border-radius: 150px;
59+
background-color: qconicalgradient(cx:0.5, cy:0.5, angle:90, stop:{stop1}
60+
rgba(255, 0, 55, 255), stop:{stop2} rgba(255, 0, 0, 30));
61+
}"""
62+
63+
val = (self.nivel)/4.91
64+
65+
stop1 = str(abs(val - 0.001))
66+
stop2 = str(val)
67+
68+
valor1 = int(float(stop1)*1000)
69+
valor2 = int(float(stop2)*1000)
70+
if (valor1>=0 and valor2<=1000) and (valor2>=0 and valor1<=1000):
71+
nuevo_estilo = estilo.replace('{stop1}', stop1).replace('{stop2}', stop2)
72+
self.ui.voltaje.setText(str(self.nivel))
73+
self.ui.progressbar.setStyleSheet(nuevo_estilo)
74+
75+
if __name__ == "__main__":
76+
app = QtWidgets.QApplication(sys.argv)
77+
mi_app = MiApp()
78+
mi_app.show()
79+
sys.exit(app.exec_())
Lines changed: 132 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,132 @@
1+
# -*- coding: utf-8 -*-
2+
3+
# Form implementation generated from reading ui file 'progressBarCircular.ui'
4+
#
5+
# Created by: PyQt5 UI code generator 5.15.4
6+
#
7+
# WARNING: Any manual changes made to this file will be lost when pyuic5 is
8+
# run again. Do not edit this file unless you know what you are doing.
9+
10+
11+
from PyQt5 import QtCore, QtGui, QtWidgets
12+
13+
14+
class Ui_MainWindow(object):
15+
def setupUi(self, MainWindow):
16+
MainWindow.setObjectName("MainWindow")
17+
MainWindow.resize(528, 459)
18+
self.centralwidget = QtWidgets.QWidget(MainWindow)
19+
self.centralwidget.setObjectName("centralwidget")
20+
self.verticalLayout = QtWidgets.QVBoxLayout(self.centralwidget)
21+
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
22+
self.verticalLayout.setSpacing(0)
23+
self.verticalLayout.setObjectName("verticalLayout")
24+
self.frame = QtWidgets.QFrame(self.centralwidget)
25+
self.frame.setStyleSheet("background-color: rgb(213, 213, 213);")
26+
self.frame.setFrameShape(QtWidgets.QFrame.StyledPanel)
27+
self.frame.setFrameShadow(QtWidgets.QFrame.Raised)
28+
self.frame.setObjectName("frame")
29+
self.progressbar = QtWidgets.QFrame(self.frame)
30+
self.progressbar.setGeometry(QtCore.QRect(110, 60, 300, 300))
31+
self.progressbar.setMinimumSize(QtCore.QSize(300, 300))
32+
self.progressbar.setStyleSheet("QFrame{\n"
33+
"border-radius: 150px;\n"
34+
"background-color: qconicalgradient(cx:0.5, cy:0.5, angle:90, stop: {stop1} rgba(255, 0, 0, 0), stop:{stop2} rgba(255, 0, 95, 255));\n"
35+
"\n"
36+
"\n"
37+
"\n"
38+
"}")
39+
self.progressbar.setFrameShape(QtWidgets.QFrame.StyledPanel)
40+
self.progressbar.setFrameShadow(QtWidgets.QFrame.Raised)
41+
self.progressbar.setObjectName("progressbar")
42+
self.circulo = QtWidgets.QFrame(self.progressbar)
43+
self.circulo.setGeometry(QtCore.QRect(20, 20, 260, 260))
44+
self.circulo.setMinimumSize(QtCore.QSize(260, 260))
45+
self.circulo.setStyleSheet("QFrame{\n"
46+
" \n"
47+
" background-color: rgb(0, 0, 255);\n"
48+
" border-radius: 130px;\n"
49+
"\n"
50+
"\n"
51+
"}")
52+
self.circulo.setFrameShape(QtWidgets.QFrame.StyledPanel)
53+
self.circulo.setFrameShadow(QtWidgets.QFrame.Raised)
54+
self.circulo.setObjectName("circulo")
55+
self.voltaje = QtWidgets.QLabel(self.circulo)
56+
self.voltaje.setGeometry(QtCore.QRect(51, 100, 111, 68))
57+
self.voltaje.setStyleSheet("font: 85 36pt \"Arial \";\n"
58+
"color: rgb(255, 255, 255);")
59+
self.voltaje.setAlignment(QtCore.Qt.AlignCenter)
60+
self.voltaje.setObjectName("voltaje")
61+
self.label_2 = QtWidgets.QLabel(self.circulo)
62+
self.label_2.setGeometry(QtCore.QRect(170, 100, 37, 68))
63+
self.label_2.setStyleSheet("font: 85 36pt \"Arial \";\n"
64+
"color: rgb(255, 255, 255);")
65+
self.label_2.setAlignment(QtCore.Qt.AlignCenter)
66+
self.label_2.setObjectName("label_2")
67+
self.label = QtWidgets.QLabel(self.circulo)
68+
self.label.setGeometry(QtCore.QRect(60, 190, 141, 20))
69+
self.label.setStyleSheet("font: 63 12pt \"Segoe UI Semibold\";\n"
70+
"color: rgb(255, 255, 255);")
71+
self.label.setAlignment(QtCore.Qt.AlignCenter)
72+
self.label.setObjectName("label")
73+
self.actualizar = QtWidgets.QPushButton(self.frame)
74+
self.actualizar.setGeometry(QtCore.QRect(220, 30, 75, 23))
75+
self.actualizar.setStyleSheet("QPushButton{\n"
76+
"border:3px solid rgb(0, 0, 255);\n"
77+
"font: 87 9pt \"Arial Black\";\n"
78+
"}\n"
79+
"\n"
80+
"QPushButton:hover{\n"
81+
"border:3px solid rgb(255, 0, 0);\n"
82+
"font: 87 9pt \"Arial Black\";\n"
83+
"}\n"
84+
"")
85+
self.actualizar.setObjectName("actualizar")
86+
self.layoutWidget = QtWidgets.QWidget(self.frame)
87+
self.layoutWidget.setGeometry(QtCore.QRect(20, 390, 511, 28))
88+
self.layoutWidget.setObjectName("layoutWidget")
89+
self.horizontalLayout = QtWidgets.QHBoxLayout(self.layoutWidget)
90+
self.horizontalLayout.setContentsMargins(0, 0, 0, 0)
91+
self.horizontalLayout.setObjectName("horizontalLayout")
92+
self.desconectar = QtWidgets.QPushButton(self.layoutWidget)
93+
self.desconectar.setStyleSheet("background-color: rgb(170, 0, 255);\n"
94+
"font: 87 9pt \"Arial Black\";")
95+
self.desconectar.setObjectName("desconectar")
96+
self.horizontalLayout.addWidget(self.desconectar)
97+
self.conectar = QtWidgets.QPushButton(self.layoutWidget)
98+
self.conectar.setStyleSheet("background-color: rgb(0, 170, 0);\n"
99+
"font: 87 9pt \"Arial Black\";")
100+
self.conectar.setObjectName("conectar")
101+
self.horizontalLayout.addWidget(self.conectar)
102+
self.puertos = QtWidgets.QComboBox(self.layoutWidget)
103+
self.puertos.setObjectName("puertos")
104+
self.horizontalLayout.addWidget(self.puertos)
105+
self.velocidad = QtWidgets.QComboBox(self.layoutWidget)
106+
self.velocidad.setObjectName("velocidad")
107+
self.horizontalLayout.addWidget(self.velocidad)
108+
self.verticalLayout.addWidget(self.frame)
109+
MainWindow.setCentralWidget(self.centralwidget)
110+
111+
self.retranslateUi(MainWindow)
112+
QtCore.QMetaObject.connectSlotsByName(MainWindow)
113+
114+
def retranslateUi(self, MainWindow):
115+
_translate = QtCore.QCoreApplication.translate
116+
MainWindow.setWindowTitle(_translate("MainWindow", "ProgressBarCircular con Arduino"))
117+
self.voltaje.setText(_translate("MainWindow", "5.0"))
118+
self.label_2.setText(_translate("MainWindow", "V"))
119+
self.label.setText(_translate("MainWindow", "VOLTAJE ARDUINO"))
120+
self.actualizar.setText(_translate("MainWindow", "Iniciar"))
121+
self.desconectar.setText(_translate("MainWindow", "DESCONECTAR"))
122+
self.conectar.setText(_translate("MainWindow", "CONECTAR"))
123+
124+
125+
if __name__ == "__main__":
126+
import sys
127+
app = QtWidgets.QApplication(sys.argv)
128+
MainWindow = QtWidgets.QMainWindow()
129+
ui = Ui_MainWindow()
130+
ui.setupUi(MainWindow)
131+
MainWindow.show()
132+
sys.exit(app.exec_())

0 commit comments

Comments
 (0)