How it Works
The code starts by trying to connect to the Arduino in all the different locations it could be on a windows machine. Once it finds the proper COM port it sets the baud rate to 9600 for the serial communication between python and the Arduino.
The GUI for python was made using the “easygui” module, available at this link: http://easygui.sourceforge.net/. This module allows the programmer to make a very simple graphical user interface consisting of message boxes, boxes with buttons, boxes with a list of choices, and boxes with fields to enter information. The programmer can also add pictures to some of the types of boxes, as well as titles. The standard msgbox can accommodate a message, a title, a picture, and and buttons by simply writing eg.msgbox(message = “message”, title = “title”, choices = [“A”, “B”, “C”], image = image.gif)
To add in the pictures that are shown when a player answers a question, one must place a .gif version of that image in the same folder as the .py program is in.
The gui is the only part of the program that is used as the player goes through the game. Button boxes are used for the questions, and message boxes are used for the correct or wrong answer screens, as well as the final screen.
Once the user clicks “Go!” the code will send a command to the Arduino in the form of a string. The Arduino is constantly checking for a signal from python to be sent to it. When it receives the signal it processes it and then picks the correct profile from the three choices for graphs 1, 2, or 3. The signal is created by incrementing a variable ‘i’ to change the duty cycle of the PWM signal. To switch the polarity of the signal to the track a high signal was sent to the relay, this allowed us to make the car travel forwards and backwards around the track using only one power circuit.