# Theory and Practice of Tangible User Interfaces

### Announcements

November 24, 2007
Reading for November 27th, are now posted. Enjoy!

October 2, 2007
To upload your thoughtless acts, create a new assignment page like any other lab. You'll see "Thoughtless Acts" listed as one of the assignment options.

May 24, 2008
This site has been archived and is no longer editable. Stay tuned for the next version, coming in the fall!

# Responsive Pillow

Project Members:
Shawna Hein

Description

A pillow which responds to the sleeper. When you lay your head on it, it plays you a lullaby (all the pretty little horses) continuously until you get up. When you turn the light off, it glows as a night light. I thought that I had soldered the blue LED but it turned out to be the red one, so this pillow also might be useful for women and men who work in the "red light" district. They can take a nap and then when it gets dark put the pillow in the window to beckon customers.

Components Used

Arduino Diecimila
3 resistors
1 red LED
1 FSR
1 photocell
1 piezo speaker
various wires
1 pillow

Arduino Code

* Pillow
* -----------
*
* This program is for a pillow. When the user puts his or her head on the pillow, a lullaby
* plays (All the pretty little horses). When they turn off the light, the pillow glows red.
*
* The calculation of the tones is made following the mathematical
* operation:
*
* timeHigh = 1/(2 * toneFrequency) = period / 2
*
* where the different tones are described as in the table:
*
* note frequency period PW (timeHigh)
* G ? ? 2500
* A ? ? 2270
* B ? ? 2000
* C 261 Hz 3830 1915
* d 294 Hz 3400 1700
* e 329 Hz 3038 1519
* f# ? ? 1350
* g 392 Hz 2550 1275
* a 440 Hz 2272 1136
* b 493 Hz 2028 1014
* c 523 Hz 1912 956
*
* (cleft) 2005 D. Cuartielles for K3
*/

int FSRPin = 0; // select the input pin for the FSR
int lightPin = 1; //select the input pin for the photocell
int ledPin = 13; //select the output pin for the LED

int FSRVal = 0; // variable to store the value coming from FSR
int lightVal = 0; //variable to store the value from the photocell

int speakerOut = 7;
char names[] = {'G','A', 'B', 'C', 'd', 'e', '#', 'g', 'a', 'b', 'c'};
int tones[] = {2500,2270, 2000, 1915, 1700, 1519, 1350, 1275, 1136, 1014, 956};
byte melody[] = "3B1p3B6d3B1p3B6d3B3d3g3#3e1p3e3d3A3B3C3A3B3C3A3C3#3e3d3#3g3G1p3G1p3G3g3e3C3d3B3G3C3B3A1p3A3Gp8p8p8p"; //All the Pretty Little Horses
int count = 0;
int count2 = 0;
int count3 = 0;
int MAX_COUNT = 48;
int statePin = LOW;

void setup() {
Serial.begin(9600);
pinMode(ledPin, OUTPUT); // declare the led1Pin as an OUTPUT
pinMode(speakerOut, OUTPUT); //declare the speaker as an OUTPUT
}

void loop() {
Serial.println(lightVal);
analogWrite(ledPin, 256-(lightVal/4)); // send info to the LED pin to light up when it is dark out
if(FSRVal>50){ //if there is enough pressure on the pillow, then play the melody
digitalWrite(speakerOut, LOW);
for (count = 0; count < MAX_COUNT; count++) {
statePin = !statePin;
for (count3 = 0; count3 <= (melody[count*2] - 48) * 30; count3++) {
for (count2=0;count2<8;count2++) {
if (names[count2] == melody[count*2 + 1]) {
digitalWrite(speakerOut,HIGH);
delayMicroseconds(tones[count2]);
digitalWrite(speakerOut, LOW);
delayMicroseconds(tones[count2]);
}
if (melody[count*2 + 1] == 'p') {
// make a pause of a certain size
digitalWrite(speakerOut, 0);
delayMicroseconds(500);
}
}
}
}
}
}

Item

Here's a video:

I know the board looks bad, but thats because there's a ton of wires going out and into the pillow

lab5pillow

lab5board