My physical controller for a previous processing sketch consists of one single potentiometer. I chose to use a pot primarily because it is more stable than many sensors, and it’s handy. The sketch I used is the spinning INTER letters. This time, instead of having the letters rotate by themselves, the pot would control their rotation speed and visibility.
Video:
The code:
int potPin = 0;
void setup() {
// put your setup code here, to run once:
Serial.begin(57600);
Serial.println("500");
}
void loop() {
// put your main code here, to run repeatedly:
if ( Serial.available() > 0) {
int inByte = Serial.read();
Serial.println( analogRead(potPin));
}
}
import processing.serial.*;
Serial myPort;
//float alpha = map(sWeight, 10, 30, 170, 200);
float rotArray[] = new float [4];
float rotIncrease;
float c;
void setup() {
size(800, 800);
myPort = new Serial( this, "/dev/cu.usbserial-DA01LJIV", 57600);
myPort.bufferUntil('\n');
stroke(c);
strokeWeight(20);
}
void draw() {
fill(0, 60);
rect(0, 0, 800, 800);
rotArray[0] = 1.0;
for ( int i=0; i<rotArray.length; i++) {
rotArray[i] += rotIncrease/180;
}
pushMatrix();
translate(width/2, height/2);
rotate(radians(rotArray[1]));
charI();
rotate(radians(rotArray[1]));
charN();
rotate(radians(rotArray[2]));
charT();
rotate(radians(rotArray[3]));
charE();
rotate(radians(rotArray[3]));
charR();
popMatrix();
}
void charI() {
stroke(c);
strokeWeight(20);
line(0, 0, 40, 0);
line(0, 60, 40, 60);
line(20, 0, 20, 60);
}
void charN() {
line(60, 20, 60, 60);
line(60, 20, 90, 60);
line(90, 60, 90, 20);
}
void charT() {
line(80, 40, 120, 40);
line(100, 40, 100, 90);
}
void charE() {
line(140, 60, 180, 60);
line(140, 60, 140, 110);
line(140, 85, 170, 85);
line(140, 110, 180, 110);
}
void charR() {
line(200, 100, 200, 180);
noFill();
arc(200, 120, 70, 40, PI+HALF_PI, TWO_PI+HALF_PI);
line(200, 130, 240, 170);
}
void serialEvent(Serial myPort) {
String input = myPort.readString();
float val = float(input);
println(val);
c = map(val, 0, 1023, 0, 255);
rotIncrease = map(val, 0, 1023, 0, 360);
myPort.write('x');
}