Step 5: Programming the User Interface
In order for Python to communicate with the Arduino, it needs the Pyserial module. Once this is installed, you can read and write to the Arduino over the serial connection.
In my program, whenever a button is clicked, the button calls a function which writes the number of the button to the Arduino. Using that number, the Arduino figures out which LED the number corresponds to, and switches the state of that LED.
The Python file for the UI is attached below. When running it, there are a few things to note:
If you run the file in Windows, it is advisable to simply double click the file instead of opening it in IDLE (the python IDE) and running it from there. Also, you will have to set the serial port to use within the code. By default, it is set to 2, which corresponds to COM3 on Windows.
Mac users: I have not tested the program on a mac. Please let me know if there are any problems with it, so I can try to fix them. Python sometimes behaves differently on Macs, especially when dealing with graphics stuff.