How to code channels for image manipulations

edited March 2016 in Raspberry PI

Hello, I am working in processing to create a code that would change images based on sensor inputs from a Raspberry Pi and an Arduino. I've figured out how to get the two to talk to my code using space brew library. However what I want to do is to map the sensor's inputs to RGB values (0-255), and then have processing generate images based on those values in real time.

I have no idea how to approach this. I had one idea of using pixels from an image to be stored in the sketch, just so that processing is still doing something when people aren't activating the sensors. But the idea is that the image would change over time/create something new when sensor inputs are entered.

This is my current code that we used to test the sensor. Right now when the sensor is activated, numbers generate and change depending on how close you are to the sensor. Any ideas of how to approach this/ what I should do in the draw loop?

/* * Base Example * * Sketch that features the basic building blocks of a Spacebrew client app. * // SpaceBrew Library added. */

PFont f; // The radius of a circle float r = 100;

import spacebrew.*;

String server="192.168.1.57"; //String server="sandbox.spacebrew.cc"; String name="OldNorthTest"; String description ="Hello, Old North!!";

String message = "Hello, Old North!";

Spacebrew sb;

void setup() { size(600, 400);

f = createFont("Georgia",40,true); textFont(f); // The text must be centered! textAlign(CENTER); smooth();

// instantiate the sb variable sb = new Spacebrew( this );

// add each thing you publish to // sb.addPublish( "buttonPress", "boolean", false );

//add each thing you subscribe to sb.addSubscribe( "color", "string" );

// connect to spacebrew sb.connect(server, name, description );

}

void draw() { // do whatever you want to do here // doing a basic text draw here

background(255);

// Start in the center and draw the circle translate(width / 2, height / 2); noFill(); stroke(0); ellipse(0, 0, r2, r2);

// We must keep track of our position along the curve float arclength = 0;

// For every box for (int i = 0; i < message.length(); i++) { // Instead of a constant width, we check the width of each character. char currentChar = message.charAt(i); float w = textWidth(currentChar);

// Each box is centered so we move half the width
arclength += w/2;
// Angle in radians is the arclength divided by the radius
// Starting on the left side of the circle by adding PI
float theta = PI + arclength / r;    

pushMatrix();
// Polar to cartesian coordinate conversion
translate(r*cos(theta), r*sin(theta));
// Rotate the box
rotate(theta+PI/2); // rotation is offset by 90 degrees
// Display the character
fill(0);
text(currentChar,0,0);
popMatrix();
// Move halfway again
arclength += w/2;

} }

void onRangeMessage( String name, int value ){ println("got range message " + name + " : " + value); }

void onBooleanMessage( String name, boolean value ){ println("got boolean message " + name + " : " + value);
}

void onStringMessage( String name, String value ){ println("Hello" + name + " : " + value);
message = value ; }

void onCustomMessage( String name, String type, String value ){ println("got " + type + " message " + name + " : " + value);
}

Sign In or Register to comment.