xxxxxxxxxx
54
// Visualization of data from EVM board:
// https://github.com/mitmedialab/TI_EVM_logger
var host = 'localhost:8080';
var socket;
var SensorValues = [];
var xc, yc, norm;
var n = 1.8;
function setup() {
createCanvas(600, 600);
strokeWeight(3);
socket = new WebSocket('ws://' + host);
socket.onmessage = readMessage;
xc = width / 2; // x center
yc = height / 2; // y center
norm = min(xc, yc) * 2 / 3; // line length
}
function readMessage(event) {
// make an array of strings:
SensorValues = split(event.data, ',');
// println(SensorValues); // use the data...
}
// visualization with 4 circles moving in function of the data
function draw() {
background(255, 150);
// reference circle
stroke(200); // grey
fill(0, 0);
ellipse(xc, yc, norm*2, norm*2);
// raw
stroke(255, 0, 0);
angle = radians(n*(SensorValues[1] - SensorValues[0]));
bent_line(angle);
}
function bent_line(a) {
var xi = int(cos(a) * norm);
var yi = int(sin(a) * norm);
line(xc,yc , xc+xi,yc+yi);
xi = int(cos(PI) * norm);
yi = int(sin(PI) * norm);
line(xc,yc , xc+xi,yc+yi);
}