Simple Tkinter

This week I decided to use my distance input device board, mainly because it was one of the only ones with an FTDI cable attached to it. To start off I slightly changed the existing python Tkinter code that works with the distance input device. Instead of having a moving bar that slides back and forth, I had a difference number of rectangles appear that would reflect the distance. The difficulty of this was removing rectangles when moving from a bigger distance to a smaller distance. To accomplish this, at the beginning of every loop I created a white rectangle to go over everything and then created new indicator rectangles to go on top of it corresponding to the distance. While this probably isn't the best code practice it worked!

The code can be found here for the c code and for the python Tkinter code.

Brick Breaker

Because the Tkinter code was sorto of a cop out, especially because it was based strongly off example code, I decided to make something better. I decided to make a game that was controled by the distance device.

I made the game Brick Breaker based off this website's tutorial. After ensuring that the game works using the keyboard left and right I moved on to incorporating the distance input.

To start off, I had to change the serial output that was coming from the distance device. Instead of returning both a high and low, I did the calculation for centimeters within the board's code. Thus I could return the distance as a single number reflecting the distance of the device. Additionally I didn't want to deal with matching up the 1, 2, 3, 4 serial outputs that occured in the original code. Instead I only returned the distance without any guiding outputs.

After several attempts, I was able to connect the serial output of the distance device with moving the controller in brick breaker. The main issue was that the controller moved at a delay when compared to moving the device. After some debugging, I realized that the distance device was writing much faster than the brick breaker code was able to read it. Thus I read in a "waste" value from the distance device that was never used. This allowed me to read in the outputs from the distance device at the right speed to reflect moving the distance device. Thus, brick breaker controled by a distance input device was born.

I had to go back and tune the c code and python code together. The movements on the sonar device was reading in as lower numbers, so the bar on brick breaker would not move very much in comparison to the sonar device moving. Thus I multiplied the output in the sonar device as well as the conversion from the ouptput to x position in the game by constant numbers until it inutively fit the natural movement.

The c code can be found here and the python code can be found here.