Force Sensor on Flute

Assignment: Sensing PART II: Force Sensitive Resistors and Photocells

Collaborators: heatherfrasch

As research for my mid term project in how to augment the flute, I attached the force sensor to one of the lower keys.  I like how it's the same size as the key, and it's in a place, which would not always be used. I only use those lower keys when I make percussive sounds with the keys alone. This way I can decide when I want to touch the sensor, and when I don't.

I need to find a better way to attach the sensor. My tape method is quite flimsy.

At the moment I have it controlling the video using aruduino and processing for the assignment . Eventually, I will connect it to my other board which I can use to control sound in a music program that I use.

I've attached pictures and the code for the first part of the assignment.

/*
* Resistive Sensor Input
* Takes the input from a resistive sensor, e.g., FSR or photocell
* Dims the LED accordingly, and sends the value (0-255) to the serial port
*/
int sensorPin = 0;  // select the input pin for the sensor
int ledPin = 11;    // select the output pin for the LED
int val = 0;        // variable to store the value coming from the sensor
void setup() {
Serial.begin(9600);
}
void loop() {
val = analogRead(sensorPin); // read the value from the sensor, 0-1023
analogWrite(ledPin, val/4);  // analogWrite (dimming the LED) can be between 0-255
Serial.println(val/4);       // writing the value to the PC via serial connection
delay(50);                   // rest a little...
}

 

/*
* Arduino Ball Paint
* (Arduino Ball, modified)
* ----------------------
*
* Draw balls randomly on the screen, size controlled by a device
* on a serial port.  Press space bar to clear screen, or any
* other key to generate fixed-size random balls.
*
* Receives an ASCII number over the serial port,
* terminated with a carriage return (ascii 13) then newline (10).
*
* This matches what Arduino's " Serial.println(val)" function
* puts out.
*
* Created 25 October 2006
* copyleft 2006 Tod E. Kurt <tod@todbot.com
* http://todbot.com/
*/
import processing.serial.*;
// Change this to the portname your Arduino board
String portname = "/dev/tty.usbserial-A9007LDc"; // or "COM5"
Serial port;
String buf="";
int cr = 13;  // ASCII return   == 13
int lf = 10;  // ASCII linefeed == 10
void setup() {
size(300,300);
frameRate(10);
smooth();
background(40,40,40);
noStroke();
port = new Serial(this, portname, 9600);
}
void draw() {
}
void keyPressed() {
if(key == ' ') {
background(40,40,40);  // erase screen
}
else {
int x = int(random(0,width));
int y = int(random(0,height));
drawball(x,y, 50);
}
}
// draw balls
void drawball(int x, int y, int r) {
for (int i=0; i<100; i++ ) {
fill(100-i,i,550);
ellipse(x,y,r,r);
}

}
// called whenever serial data arrives
void serialEvent(Serial p) {
int c = port.read();
if (c != lf && c != cr) {
buf += char(c);
}
if (c == lf) {
int val = int(buf);
println("val="+val);
int x = int(random(0,width));
int y = int(random(0,height));
drawball(x,y,val);
buf = "";
delay (50);
//    delay(100);
background(40,40,40);  // erase screen
}
}