Week 13: Interface and Application Programming



Individual Assignments:
1) Write an application that interfaces a user with an input and or output device that you made


INDIVIDUAL ASSIGNMENT


Processing

I first tryed out Processing as it was the first language we discussed "in class". So I started looking at the language reference to understand and learn a bit of synthax. Me and my collegues had the chance to walk through a code with our instructor and this is the way I modifyed the code to make the LED on my Arduino board blink using a serial port (to make my Arduino board and and the interface communicate):


Code Arduino


Responsive image


Code Processing

Responsive image


This is the result:


LED Processing from Olivia De Masi on Vimeo.

Now I wanted to do an interface final project ways so I decided to create an interface with two buttons: when the first is clicked the interface should get back to the user saying the type and weight of the product "Grain 500gr" in this case; when the second button is clicked it should tell the user the cost of that food "€3.50". So I set up the code in processing but something is not working. I'm guessing I'm still not fluid with variables so the interface gives the same feedback whether I click on the first or on the second button. This is the code:


Responsive image


After a consult with my instructor and some tests I new my variables where not incorrect but not needed, so I changed them and I changed what was inside the mousepressed function indicating the exact coordinates of the two buttons. So this is the code:



And this is how my interface works now:


Touch Sensor Interface

To practice more with this language I made an interface connected to this touch sensor. So these are the codes:





Temperature Sensor Interface

My idea was to create an interface with a button which returns the temperature when the interface's button is pressed. So first of all I connected this sensor to my Arduino board. I then wrote the two codes: first by opening the same serial port to garantee the connection and the trasmission of data, then I drew two flowcharts to help me visualize the instructions to give to Processing and Arduino:


Responsive image


Responsive image


The most helpfull thing for me was to study and check all the serial functions:


Responsive image




Responsive image


So I went to serch on my bibles, the language reference pages of Arduino and Processing and I tried to follow my flowcharts as much as I could. There's still something wrong with my codes because, the arduino serial monitor writes the right temperature but when I try to read those data on my Processing interface it only returns a series of zeros. I have have to find the mistakes. These are the codes:




I had to add a "Serial.available()" to make the serial listen and a "char" variable to store the data in my arduino code. So this is the final code:



I did pretty much the same in my processing: code I added the "Serial.available()" command for the serial port to wait for the data that Arduino would send, and I added a variable "temperature=miaPorta.readString()" to read and store those data.



Let's see how it works now!



Links

- https://processing.org/
- https://processing.org/reference/
- http://wiki.seeedstudio.com/Grove-Touch_Sensor/
- http://wiki.seeedstudio.com/Grove-Temperature_Sensor/
- https://www.arduino.cc/reference/en/