Lab 5 - DJ Gloves
Description
The goal of this homework is to integrate inputs and outputs into an embodied interface. I used a Piezo speaker, light sensor and force sensitive resistor (FSR) all connected to my breadboard.
DJ's these days have been known to spin records, false records connected to iPods, and just press buttons on iPods during their sets. Well not anymore. Now DJ's can use the DJ gloves to change songs while rocking out.
I used the FSR sensor inside one glove to change the notes played on the Piezo. I also used the light sensor to alter the output when you press the FSR all the way.
Components Used
Arduino Micro-controller
Resistors
Wires/Bread Board
Sensors (FSR and Photocell)
Ambient light
Piezo Speaker
Smelly snow gloves
Arduino Code
/* Plays a tune when the force sensed is over a certain threshold
*/
int inputPin = 1; // select the input pin for the FSR
int sensorPin = 2; // select the input pin for the light sensor
int speakerPin = 7;
int sensorVal = 0; // initiate the variable
byte names[] = {'c', 'd', 'e', 'f', 'g', 'a', 'b', 'C'};
int tones[] = {1915, 1700, 1519, 1432, 1275, 1136, 1014, 956};
byte melody1[] = "2C1c";
byte melody2[] = "1f1a";
byte melody3[] = "1d1d";
byte melody4[] = "2f2e2b2a";
// count length: 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0 1 2 3 4 5 6 7 8 9 0
// 10 20 30
int MAX_COUNT = 24;
int val = 0;
void setup() {
pinMode(speakerPin, OUTPUT);
Serial.begin(9600);
Serial.println("ready");
}
void loop() {
digitalWrite(speakerPin, LOW);
val = analogRead(inputPin);
Serial.println(val);
if (val > 0 && val < 150) {
} else if (val >= 150 && val < 400) {
playSong1();
} else if (val >= 400 && val < 800) {
playSong2();
} else if (val >= 800) {
sensorVal = analogRead(sensorPin); // read the value of the sensor
Serial.println(sensorVal);
if (sensorVal > 100){ // if sensor is not covered play a different tune
playSong3();
} else {
playSong4();
}
}
}
void playSong1() {
int count = 0;
int count2 = 0;
int count3 = 0;
digitalWrite(speakerPin, LOW);
for (count = 0; count < MAX_COUNT; count++) {
for (count3 = 0; count3 <= (melody1[count*2] - 48) * 30; count3++) {
for (count2=0;count2<8;count2++) {
if (names[count2] == melody1[count*2 + 1]) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tones[count2]);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tones[count2]);
}
}
}
}
}
void playSong2() {
int count = 0;
int count2 = 0;
int count3 = 0;
digitalWrite(speakerPin, LOW);
for (count = 0; count < MAX_COUNT; count++) {
for (count3 = 0; count3 <= (melody2[count*2] - 48) * 30; count3++) {
for (count2=0;count2<8;count2++) {
if (names[count2] == melody2[count*2 + 1]) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tones[count2]);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tones[count2]);
}
}
}
}
}
void playSong3() {
int count = 0;
int count2 = 0;
int count3 = 0;
digitalWrite(speakerPin, LOW);
for (count = 0; count < MAX_COUNT; count++) {
for (count3 = 0; count3 <= (melody3[count*2] - 48) * 30; count3++) {
for (count2=0;count2<8;count2++) {
if (names[count2] == melody3[count*2 + 1]) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tones[count2]);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tones[count2]);
}
}
}
}
}
void playSong4() {
int count = 0;
int count2 = 0;
int count3 = 0;
digitalWrite(speakerPin, LOW);
for (count = 0; count < MAX_COUNT; count++) {
for (count3 = 0; count3 <= (melody4[count*2] - 48) * 30; count3++) {
for (count2=0;count2<8;count2++) {
if (names[count2] == melody4[count*2 + 1]) {
digitalWrite(speakerPin, HIGH);
delayMicroseconds(tones[count2]);
digitalWrite(speakerPin, LOW);
delayMicroseconds(tones[count2]);
}
}
}
}
}