Description
I built an "instrument" that can be used to control a very simple visualizer in Processing. It is meant to be used to generate a visual display to match music. A stroked circle is continously generated; its size is controlled by the photocell (bringing your hand closer to the photocell will increase the size of the circle). This could be used to show the melody of the music, or the intensity. In addition, tapping the force sensor generates filled circles that are larger with stronger hits; this could be used to show percussive elements in the music. I used a cotton pad as the transducer for the force sensor to provide tactile and visual feedback for how much force is being applied to the sensor; it's hard to tell with the flat bare sensor, but the amount by which the cotton pad is depressed shows how much force is being applied.
Components Used
1- Arduino Uno
2- 1K Ω Resistor
1- Breadboard
1- Force sensitive resistor
1- Photocell
1- Cotton pad
Code
Arduino:
/*
Serial input and output
*/
int forceSensorPin = A0;
int forceSensorValue = 0;
int photocellSensorPin = A1;
int photocellSensorValue = 0;
int rLedPin = 9;
int gLedPin = 10;
int bLedPin = 11;
void setup() {
pinMode(rLedPin, OUTPUT);
pinMode(gLedPin, OUTPUT);
pinMode(bLedPin, OUTPUT);
Serial.begin(9600);
}
void loop() {
Serial.print(analogRead(forceSensorPin));
Serial.print(", ");
Serial.print(analogRead(photocellSensorPin));
Serial.print(", ");
Serial.println();
delay(100);
}
Processing:
import processing.serial.*;
Serial myPort; // Create object from Serial class
String portName = "COM6";
String arduinoIn; // Data received from the serial port
int screenWidth = 600;
int screenHeight = 400;
int minPhotocellValue = 1000;
int maxPhotocellValue = 1000;
void setup() {
myPort = new Serial(this, portName, 9600);
size(screenWidth, screenHeight);
frameRate(10);
smooth();
background(0, 0, 0);
rectMode(CENTER);
ellipseMode(CENTER);
}
int[] sensors = {0, 0, 0};
float[] scaledSensors = {0, 0};
void draw() {
if(myPort.available() > 0) {
arduinoIn = myPort.readStringUntil('\n');
}
if(arduinoIn != null) {
sensors = int(split(arduinoIn, ", "));
if(sensors.length > 2) {
if(sensors[1] < minPhotocellValue && sensors[1] > 0) {
maxPhotocellValue -= (minPhotocellValue - sensors[1]);
minPhotocellValue = sensors[1];
}
scaledSensors[0] = ((float) sensors[0])/1000;
scaledSensors[1] = ((float) (1000 - (sensors[1] + minPhotocellValue)))/1000;
}
}
println(sensors[1]);
println(scaledSensors[1]);
fill(0, 0, 0, 30);
rect(screenWidth/2, screenHeight/2, screenWidth, screenHeight);
stroke(255- 255*scaledSensors[1], 0, 255*scaledSensors[1], 200);
strokeWeight(5);
fill(0, 0, 0, 0);
ellipse(screenWidth/2, screenHeight/2, screenHeight*scaledSensors[1], screenHeight*scaledSensors[1]);
stroke(0, 0, 0, 0);
fill(255*scaledSensors[0], 0, 255 - 255*scaledSensors[0]);
ellipse(screenWidth/2, screenHeight/2, screenHeight*scaledSensors[0], screenHeight*scaledSensors[0]);
}
- Login to post comments