Exercise 16 - Interface and Application Programming

Write an application that interfaces with an input and/or output device that you made

Python

During Fab Academy was the very first time that I used Python or similar programming language.

I tested Python in exercise 13 - input device with a light sensing board and also in exercise 15 - networking and comunication with two serial comunicating boards. I got them both running.

I followed the tutorial of Codeacademy about Python in order to be able of modify the scripts above.

I modified the dimension of the window doing it 2 times larger than the original, by typing WINDOW = 1200 # window size:

I played a little more with this script.

I changed the eps value from 0.5 to 0.1. This value is able to filter the noise and to smooth the changes of the serial data on the screen. Below on the video you can see how smoother are the changes now.
From the code:
filter = (1-eps)*filter + eps*value

I played also with the X variable. This value change the position of the edge between the two rectangles on the dial. It is not a good idea to change it, unless you have understood the math behind.
From the code:
x = int(.2*WINDOW + (.9-.2)*WINDOW*filter/1024.0)
canvas.coords('rect1',.2*WINDOW,.1*WINDOW,x,.25*WINDOW) canvas.coords('rect2',x,.1*WINDOW,.9*WINDOW,.25*WINDOW)

I found in the script an interesting function that is ord(c). This function is able to give an integer (numbers) from a string (characters). This part is very important to translate the information coming through serial comunication from the light sensor-board in to a number that could be used by the maths of Python.
From the code:
low = ord(ser.read())
high = ord(ser.read())

The last part modifies the colors and the positions of the rectangles and of the text. These rectangles are not real rectangle-functions but two canvas-functions drawn on the top of an other.
I changed color of the rectangles.
I changed also the positions moving the rectangles to the bottom of the window and moving the text on the top-center.
I changed also size, color and style of the text.

Finally the video where it is possible to see all the modifications.