Interface and Application Programming

This weeks assignment was to make a interface program and I used Python and Arduino. First is to code the board. I took the Software serial example code and took some of the code to my button code from week 7 because I used that to interface with python. First was to get to read what I'm sending from the board with pressing a button so I know that code will work when coding with python. I made a code so if I press the button it lights up and in the serial monitor would display a small b when idle and with the button held down displaying capital B. Next up is to code the python so I grabbed Niels Motion python code and edited that. So I set the correct baudrate and launched the program and it worked, so what's left is to code it to talk with my button. To make python change it's state, I made it listen so if the board is going to send "b" or "B" and make it change state depending on what the board is sending.

So I put in "if(ser.inwaiting()>0):" so when it launches it waits for me to push the button to change and added/changed more code in there. I put in "if ( char == 'b' )" after the inwaiting code because the board is always sending that when the button isn't pressed. Then I put "elif ( char == 'B' )" so when the button is pressed the state changes. Underneath those I changed what each command is going to do. I got an error message since the placement is important in Python and moved eveything to a correct place with the tab key. Then I got another error that said "'Serial' object has no attribute 'inwaiting'" so the w needed to be in capital so changing that and running the py works. Then I changed the "window" setting to change the size, the text and colour of the boxes and voila!

And here is the code working! When I press the button it changes colour and the text changes into capitals.

Python File
Arduino file
Right click and save link as to download the code.