Week 13: Interface and Application programming
The assignment for this week: Write an application that interfaces with an input and/or output device that you made.
Emma gave us a lecture on making Processing communicate with the port that recieves data from the input/output board that we programmed using Arduino IDE. After watching (and reading) 8 or so tutorials from the Processing website and in the YouTube channel Coding Train, I decided to write a program for a bar chart that plots the sensor values of my stretch sensor input board of week 11.
Changing background color gradually with stretch sensors
To get comfortable with Processing, I tried one of Emma's examples to change the background color gradually with the sensor value. I programmed my board with the program I used in the week of Input Devices. It is called Stretch Serial. And you can find it under this paragraph. Then I attached my input board to the computer with the FTDI cable, changed the PORT name for the port my computer uses (COM9) and ran the code. I saw the background color chaging to different shades of grey while stretching my sensor. As this is just to practice and I hardly changed anything to the codes, I will not show and explain the code or show a video of the result. For the next two learning experiences, I will.
If Else changing background RGB colors with stretch sensors
Now I wanted to practice a little with conditional coding; using
if else. I wanted the background color to change if the sensor value was under a certain value, in between two certain values and above a certain value. I used this tutorial as a reference and typed my code. First I made a mistake trying to use the
=. Because in the code provided by Emma there is a line
if (val == null), I thought this would be the way to write if I refer to a condition where the value is equal to a certain value. So I included this in my first attempt. This got me the error
The operator == is undefined for the argument type(s) int boolean Then I changed
=. That did not help. As the error is refering to my boolean operator, I though: let's check out a tutorial on boolean expression in Processing. I found it here. Now I know that the correct operator to use here is
>=or used with the bigger then sign, which CSS will not let me use here.
Bar chart from stretch sensor input
And now for something completely different. I want to make the value of the stretch sensor visible in a bar chart. I figured this would be a rectangle changing in length according to the sensor value. A fact to keep in mind here is that the y-axis in Processing has a value 0 at the top of the canvas. So the actual height of the bar would be
canvas height -sensor value. The canvas height is defined in void set up. first I made the mistake of also setting the background color in void set up. If you do this, successive bars will overlap eachother. Background color does not return in between two value measurements. When I set the background color in void draw, the background color is reset for every value of val_aux. See the pictures for further explaination of the code.
Of course I could do more interesting things than this. I could add an x- and y-axis and set values along it. Also my input board can connect two sensors. I could combine these two sensors in a bar chart. In fact I would love to spend a whole week on trying out different kind of coding in Processing. It is just so much fun puzzling, failing and succeeding in this. But I am not going to use this application programming in my final project. And I need to catch up with some documentation, so I will leave it at this.