Tuan Makes Almost Anything

MAS.863/4.140/6.S976

Interfacing Devices: Virtual Button

My idea behind this week's project is to replace the physical button in my final project with a virtual button on my computer. I tried using two languages: python and javascript, and was excited because I wanted a reason to use node.js for the first time! Thankfully I did a bit of interfacing in Week 8, via python, so to start I only had to slightly modify it.

  • Technology: TKinter & Node
  • Week: 11

So my goal is to make something similar to rx.py from Week 8's project except with a button controlling when to start recording and when to stop recording. I started with python since rx.py was in python, so I looked up Tkinter tutorials. However, I noticed that Tkinter stops all execution of code once top. Upon googling for a workaround (like timer interrupts or something) I found a stack overflow thread about this exact problem.

Sketchy hack

It's a function that just sketchily calls on itself every millisecond (the fastest a Tkinter widget can go) and does ser.read() several times. However, I got an error when from the change_state() function when trying to change the variable "recording". Upon more googling, I learned this very strange quirk about python: functions assume that all variable are local unless it is very obvious that they are not (like specifying that the variable is nonlocal or global). I fixed this by being more hacky and encapsulating the global variables xlist and recording as lists!

Even sketchier hack

At the moment, my code only creates a button. I'd like for it to plot the sound after each cycle of recording as part of the window.