For this assignment I did an interface to the “Synchronous light reflection board” input data.
I used the Processing language and Openprocessing library.
I am very grateful to the Fab Lab SP companions especially programmer Radamés Ajna to do this assignment.
Firstly I tried to understand what´s going on with hello reflect codes.
The Hello.reflect.c code
Basically, the hello.reflect.c code ´s core is:
for (count = 0; count < nloop; ++count) {
//
// LED off
//
set(led_port, led_pin);
//
// initiate conversion
//
ADCSRA |= (1 << ADSC);
//
// wait for completion
//
while (ADCSRA & (1 << ADSC))
;
//
// save result
//
off += ADC;
//
// LED on
//
clear(led_port, led_pin);
//
// initiate conversion
//
ADCSRA |= (1 << ADSC);
//
// wait for completion
//
while (ADCSRA & (1 << ADSC))
;
//
// save result
//
on += ADC;
}
//
// send framing
//
put_char(&serial_port, serial_pin_out, 1);
char_delay();
put_char(&serial_port, serial_pin_out, 2);
char_delay();
put_char(&serial_port, serial_pin_out, 3);
char_delay();
put_char(&serial_port, serial_pin_out, 4);
char_delay();
//
// send result
//
put_char(&serial_port, serial_pin_out, (on & 255));
char_delay();
put_char(&serial_port, serial_pin_out, ((on >> 8) & 255));
char_delay();
put_char(&serial_port, serial_pin_out, (off & 255));
char_delay();
put_char(&serial_port, serial_pin_out, ((off >> 8) & 255));
char_delay();
}
This code´s core shows us that the board will send to USB the 1,2,3,4 numbers and after this, four large numbers: two “on” numbers and two “off” numbers. This “on” and “off” numbers are the environment lecture data collected by the board.
The Hello.reflect.py code
The hello.reflect.py is the script that will draw the interface to board´s input data. Basically this script will read the 1,2,3,4 numbers sequentially and the “on” (two numbers) and “off (two numbers). After reading form the USB serial the two “on” numbers, the script will execute:
on_value = (256*on_high + on_low)/nloop
That is the final “on” value, that will be screen graphically. The same happens with the “off” value. The third data is the “filter” that is calculated through this equation:
filter = (1-eps)*filter + eps*amp*(on_value-off_value)
The Processing code
With this information above I begun to work with Processing language this way:
First I import: processing.serial and Serial myPort to read the USB data. So I did a void serialEvent () that will read the 1,2,3,4 sequentially and after this the two “on” numbers and two “off” numbers. I used the Switch command with 7 cases. At the end of this read, the script do this command (same from Neil´s hello.reflect.py) :
on = (float) (on_L + on_H*256)/nloop;
off = (float) (off_L + off_H*256)/nloop;
This is the “on” and “off” final numbers, and so next script I calculate the “filter” ( same from Neil´s hello.reflect.py):
filtr = (1-eps)*filtr + eps*amp*(on-off). (I used filtr instead of filter because filter is a command in Processing).
The Interface using Processing
With this inputs, ( on, off and filtr) I designed my interface with this code from http://www.openprocessing.org/. My interest is to explore the interface.
My core´s code is:
void draw()
{
background(255);
fill(200,90,11,100);
float w_on =map(on, 0, 1024, 0, width);
for (int i=0; i < x.length; i++) {
float dia = dist(y[i], x[i], w_on, w_on);
rect(x[i], y[i], dia, dia);
}
fill(200,90,11,100);
float w_off =map(off, 0, 1024, 0, width);
stroke(255)
for (int i=0; i < x.length; i++) {
float dia = dist(w_off, y[i], w_off, x[i]);
rect(x[i], y[i], dia, dia);
}
filtr = (1-eps)*filtr + eps*amp*(on-off);
fill(200,90,11,63);
float w_filtr =map(filtr, 0, 4024, 0, width);
for (int i=0; i < x.length; i++) {
float dia = dist(x[i], filtr, filtr, y[i]);
rect(x[i], y[i], dia, dia);
}
This script designs several rectangles that responses through , on, off and filtr data collected from the board.
|