Main                    Work Space                    About Me

INTERFACE AND APPLICATION PROGRAMMING

Interface programming processing Fab Academy assignment from R.Ferrero on Vimeo.


For this week I haven’t a lot of time so I make a very simple example for the Interface and application programming assignment.

What I made is to use the hello light input board to make something change in function of the quantity of light our board sensor is reading.

 hellolight
              Hello light board

By using Processing, we make an interface wich is a square that change color in function of the quantity of light the sensor is Reading.

In processing, first we have is to load de serial library, we use this library to make the communication between processing and our serial port to read the data from the board, in this case Hello Light board, and we read the sensor data.

import processing.serial.*;

 

Serial myPort; 

int val;    

int sensorData;

int highVal;

int lowVal;

int actualVal;

After this we start with the real interface program, we test if our port is available or not, and set a variable with the actual value of the sensor read.

if (myPort.available() > 0) {   

    val = myPort.read();          

    if (val > 4) {               

      highVal = myPort.read();          

      lowVal = myPort.read();          

      actualVal = 256 * (highVal + lowVal);

      println("The actualVal is " + actualVal);

    }

Finally we set how the color of the square will change, in this case, if the read value it’s lower than 1024, we fill the squared on black, if not, we fill it on grey.

if (actualVal < 1024) {   

      fill(0);                  

    }

    else {                      

      fill(204);                

    }

As you can see on the video, there is a square that change from black to grey when the quantity of light pass a limit that we can set on the code.

Here you can download the processing code

Processing Code

That’s all for this week.

Greetings from Leon and have a nice week ;-)