import sys import time import integration as machine import serial # run if you need to get port info, on pc port should just be something like COM3 from bard import Ui_MainWindow from PyQt5.QtCore import QUrl from PyQt5.QtMultimedia import QMediaContent, QMediaPlayer from PyQt5.QtWidgets import QApplication, QMainWindow # try uploading dummy code through the arduino IDE via UF2 connection. then, click on port - a port # should appear # run to allow arduino script to run for dur (20) sec port = "COM13" # Replace with your Arduino's port baudrate = ( 115200 # make sure this matches the baud rate in the Arduino sketch (.ino file) ) dur = 5 # sec # initialize serial connection # ser = serial.Serial(port, baudrate, timeout=1) # time.sleep(2) # wait for the connection to be established preset_drinks = [ [10, 40, 56, 70, 0, True], [10, 40, 20, 60, 0, False], [0, 50, 70, 10, 40, True], ] # preset drinks, feel free to change class Window(QMainWindow, Ui_MainWindow): def __init__(self, parent=None): super().__init__(parent) self.setupUi(self) self.drink_settings = [] self.drink_number = 1 self.loaded_cup_num = 0 self.media_player = QMediaPlayer() self.connectSignalsSlots() def connectSignalsSlots(self): # starting state, connects buttons to various functions self.set_mp3() self.which_drink() self.cup_error_myo.hide() self.cup_error_preset.hide() self.cup_error_load.hide() self.max_cups.hide() self.finish_loading.setDisabled(True) self.submit_preset.clicked.connect(self.submit_drink_setting) self.submit_myo.clicked.connect(self.submit_drink_setting) self.pt.clicked.connect(lambda: self.stackedWidget.setCurrentIndex(1)) # type: ignore self.myo.clicked.connect(lambda: self.stackedWidget.setCurrentIndex(2)) # type: ignore self.drinks_confirm.clicked.connect(self.load_cup_lander) self.back_preset.clicked.connect(lambda: self.stackedWidget.setCurrentIndex(0)) # type: ignore self.back_myo.clicked.connect(lambda: self.stackedWidget.setCurrentIndex(0)) self.next_order.clicked.connect(self.restart_order) self.cancel.clicked.connect(self.restart_order) self.back_loading.clicked.connect(self.restart_order) self.confirm_order.clicked.connect(self.submit_order) self.finish_loading.clicked.connect( lambda: self.stackedWidget.setCurrentIndex(0) ) self.confirm_cup.clicked.connect(self.load_single_cup) def restart_order(self): # restarts the states self.drink_settings = [] self.drink_number = 1 self.loaded_cup_num = 0 self.which_drink() self.stackedWidget.setCurrentIndex(3) self.loaded_cup_number.setText(f"Cups loaded: {self.loaded_cup_num}") self.media_player.stop() self.max_cups.hide() self.confirm_cup.setDisabled(False) self.finish_loading.setDisabled(True) def submit_drink_setting(self): # submits the drink settings into a list if self.stackedWidget.currentIndex() == 2: self.drink_settings.append( [ self.liquid1.value(), self.liquid2.value(), self.liquid3.value(), self.liquid4.value(), self.liquid5.value(), self.stir_check.isChecked(), ] ) else: self.drink_settings.append(preset_drinks[self.drink_set.currentIndex()]) self.drink_number += 1 self.which_drink() if (self.stackedWidget.currentIndex() == 2 and self.samedrink_check_myo.isChecked()) or (self.stackedWidget.currentIndex() != 2 and self.samedrink_check_preset.isChecked()): # If "same drink" checkbox is checked, use the first drink's settings for all subsequent drinks for i in range(self.drink_num.value() - self.drink_number + 1): self.drink_settings.append(self.drink_settings[self.drink_number - 2]) self.drink_number = self.drink_num.value() + 1 if self.drink_number > self.drink_num.value(): self.stackedWidget.setCurrentIndex(4) else: self.stackedWidget.setCurrentIndex(0) def set_mp3(self): # Set the media content to the desired MP3 file url = QUrl.fromLocalFile("music/fireball.mp3") media_content = QMediaContent(url) self.media_player.setMedia(media_content) def submit_order(self): # goes to order submitted landing page, plays music print("Making drink!") self.stackedWidget.setCurrentIndex(5) self.media_player.play() QApplication.processEvents() machine.machine_make_drink(self.drink_settings, ser) def cup_detection(self): # detects whether cup is in the loading dock # return True if not machine.cup_detect(): self.cup_error_load.show() # self.confirm_cup.setDisabled(not machine.cup_detect()) else: self.cup_error_load.hide() self.confirm_cup.setDisabled(False) return machine.cup_detect() def which_drink(self): # tells user which drink they are customizing self.drink.setText(f"Drink: {self.drink_number}") self.drink_preset.setText(f"Drink: {self.drink_number}") self.drink_myo.setText(f"Drink: {self.drink_number}") def load_single_cup(self): # tells the machine that cup is ready to be loaded and loads it. If there are the right amount of cups it prompt the user forward cup_detected = self.cup_detection() if cup_detected: if self.loaded_cup_num < self.drink_num.value(): self.loaded_cup_num += 1 machine.rotate_table() self.finish_loading.setDisabled(True) self.max_cups.hide() self.cup_detection() if self.loaded_cup_num == self.drink_num.value(): self.cup_error_load.hide() self.max_cups.show() self.confirm_cup.setDisabled(True) self.finish_loading.setDisabled(False) self.loaded_cup_number.setText(f"Cups loaded: {self.loaded_cup_num}") def load_cup_lander(self): # jumps to loading cups page, starts cup detection self.stackedWidget.setCurrentIndex(6) # self.cup_detection() if __name__ == "__main__": app = QApplication(sys.argv) win = Window() win.show() sys.exit(app.exec())