Thinking Physically: brauswitch demonstration

kara_brauswitchFollowing up on the initial post about the brauswitch – the eyebrow activated headband switch. Here is some video with a simple application demonstrating it’s use. There are separate switches for both the left and right sides. The simple Arduino code listed below will indicate if the left, right or both sides have been activated. A Processing sketch reads the serial output of the device and plays a variety of sound samples.

There is something really nice about the amplification of a small facial movement and the larger audio/visual response of the sketch. It’s also nice to interact in a handsfree way. Oh! Fun. Code after the video.

Arduino code:


/* brauswitch
* robert carlsen | robertcarlsen.net
* 2-2008
*
* the brauswitch is a headband mounted switch activated by raising the eyebrows.
* the prototype version is made from burlap with conductive fabric on opposite sides
* of a small gap in the headband just above the eyebrows. raising the eyebrows closes the gap
* which closes the switch. the position of the headband needs to be adjusted carefully for proper
* action - however once situated well the brauswitch works very consistently.
*
* this code sends a byte via serial when the switch is closed:
* 1, 2 or 3 for left, right and both switches respectively
*/

#define LEFT_BROW 8
#define RIGHT_BROW 9
#define LED 3

void setup() {
Serial.begin(9600);

pinMode(LEFT_BROW, INPUT);
pinMode(RIGHT_BROW, INPUT);
pinMode(LED, OUTPUT);

}

void loop(){
int var1 = digitalRead(LEFT_BROW);
int var2 = digitalRead(RIGHT_BROW);

byte msg = 0;

if(var1 == HIGH){
digitalWrite(LED, HIGH);
msg += 1;
delay(10);
digitalWrite(LED, LOW);
}

if(var2 == HIGH){
digitalWrite(LED, HIGH);
msg += 2;
delay(100);
digitalWrite(LED, LOW);
}

if(msg>0)
Serial.print(msg,BYTE);

delay(100);
}

Processing (java) code:


// Project:         brauswitch
// File:             Brauswitch.java
// Created by:         rcarlsen, Feb 21, 2009

// Imports
import processing.core.*;
import ddf.minim.*;
import processing.serial.*;

public class Brauswitch extends PApplet {
Serial myPort;

// holder for the incoming data
byte[] data = new byte[1];

// color array
int[] c = {0x33000000,0x33ff0000,0x3300ff00,0x330000ff};
int cIndex = 0;

int timer;
int timeout = 1000;

Minim minim;
AudioSnippet bothSound,leftSound,rightSound;

public void setup() {
size(500,300);
smooth();
background(0);
noStroke();

//println(Serial.list());
myPort = new Serial(this,Serial.list()[0],9600);

minim = new Minim(this);
bothSound = minim.loadSnippet("beat.wav");
leftSound = minim.loadSnippet("msgstart.wav");
rightSound = minim.loadSnippet("msgend.wav");
}

public void draw() {
// draw a partially transparent rect over the previous frame
fill(0x33000000);
rect(0,0,width,height);

// read the serial data is available
if(myPort.available()>0){
println(myPort.available() + " bytes available");

//only expecting one byte
data = myPort.readBytes();
myPort.clear();
}

// act on the read data. it will be 0,1,2,3
if(data[0]>0){
println("Data read: " + data[0]);
cIndex = data[0];
// clear the data
data[0] = 0;

switch(cIndex){
case 1:
if(!leftSound.isPlaying())
leftSound.loop(0);
break;
case 2:
if(!rightSound.isPlaying())
rightSound.loop(0);
break;
case 3:
if(!bothSound.isPlaying())
bothSound.loop(0);
break;
}

// keep the timer going
timer = millis();
}

// fade out if the brauswitch is open
if(millis() - timer > timeout){
cIndex = 0;
if(bothSound.isLooping())
bothSound.play(); //finish the sound and stop
if(leftSound.isPlaying())
leftSound.pause();
if(rightSound.isPlaying())
rightSound.pause();
timer = millis();
}

// draw the indicator ellipse
fill(c[cIndex]);
ellipseMode(CENTER);
ellipse(this.width/2, this.height/2,200,200);
}

public void stop()
{
// always close Minim audio classes
bothSound.close();
leftSound.close();
rightSound.close();
// always stop Minim before exiting
minim.stop();

super.stop();
}
}

Posted

in

,

by

Comments

Leave a Reply