User login

Powered by Drupal, an open source content management system

Theory and Practice of Tangible User Interfaces

Lab 5: Piezo Speakers and Input/Output Coincidence

Submitted by Laura Paajanen on Wed, 10/08/2008 - 22:11

Assignment: Input / Output Coincidence Lab Assignment

Collaborators:

Assignment: Input / Output Coincidence Lab Assignment
Collaborators:

Assignment: Piezo Speakers and Input/Output Coincidence

Description

I played with programming songs, but ended up returning to the modified theremin code so that the Disco Ducky could sing his own song that matched his flashing LEDs. The Disco Ducky (also known as seizure ducky due to the end of his light flashing pattern) is an airport gift shop present from my sister. When the contacts on his belly are touched, his internal LEDs flash in a preset pattern that starts out glowing but ends up flashing – it makes for a fun "found" song. The song can be modified easily by changing the distance between Disco Ducky and the photocell, adjusting the ambient light, and changing the speed of the theremin cycles.

Components Used

  • Arduino Board
  • Piezo speaker
  • 220-ohm Resistors
  • Wire
  • Breadboard
  • USB cable
  • Laptop running Arduino
  • Potentiometer (to control volume)
  • Photocell
  • Disco ducky!

Arduino Code

/* Theremin
 * --------
 *
 *
 * Created 24 October 2006
 * copyleft 2006 Tod E. Kurt 
int potPin = 0; // select the input pin for the potentiometer
int speakerPin = 7;

int val = 0;

void setup() {
pinMode(speakerPin, OUTPUT);
beginSerial(9600);
Serial.println("ready");
}

void loop() {
digitalWrite(speakerPin, LOW);

val = analogRead(potPin); // read value from the sensor
val = val*2; // process the value a little
//val = val/2; // process the value a little

for( int i=0; i<10; i++ ) { // play it for 1 cycle – sped up for better response
digitalWrite(speakerPin, HIGH);
delayMicroseconds(val);
digitalWrite(speakerPin, LOW);
delayMicroseconds(val);
}
}