Assignment 12: Interface and application programming.
The assignment was to write an application that interfaces with an input and/or output device. My program is made in python with TKinter, a graphical user interface widget set for Python. It is an interface for the hello.light board that visualizes this weeks process:
In the movie you can see that the crocodile starts jumping as I cast a shadow over the light sensor on the board.
The process I did not have experience with any of the languages that were presented in class so I took the hello.light.45.py code provided by Neil and started manipulating it.
Working in Xcode, I changed the colours and shape of the bar that displays the sensor output. Then I tried to do something more by copypasting code from tutorials and seeing what it did. I got great help from Cynthias boyfriend, who explained what each of the initial code lines do and showed me the importance of indentation in the code for example. I also used these websites for TKinter and python that were very helpful:
Off course I made lots of mistakes before I had the code working properly. During the process the workflow was to change .py file in Xcode, saved it and then try to flash it to the microcontroller via the terminal. The terminal checks if there is an error in the code and is as nice as to tell you in which line the problem occurs.
Here's the code that makes the crocodile jump up and down, dependent of the sensor value:
#
# hello.light.45.py
#
# receive and display light level
# hello.light.45.py serial_port
#
# Neil Gershenfeld
# CBA MIT 10/24/09
#
# (c) Massachusetts Institute of Technology 2009
# Permission granted for experimental and personal use;
# license for commercial sale available from MIT
#
from Tkinter import *
import serial
WINDOW = 500 # window size
eps = 0.5 # filter time constant
filter = 0.0 # filtered value
if (len(sys.argv) != 2):
print "command line: hello.light.45.py serial_port"
sys.exit()
port = sys.argv[1]
#
# open serial port
#
ser = serial.Serial(port,9600)
ser.setDTR()
#
# set up GUI
#
root = Tk()
root.title('see you later alligator')
root.bind('q','exit')
the_canvas = Canvas(root, width=WINDOW, height=WINDOW, background='white')