Description
A ball pen which will light up and play when its lead is switched on or off, to make the interaction more interactive. It could be extended to the idea of playing the music and light when the pen is ready to write and switch them off when its not ready.
Components Used
Arduino board
1 FSR
1 10K ohm resistor
1 LED
1 220ohm resistor
1 piezo speaker
1 Ball Pen
Arduino Code
/* Entertaining pen
* --------
*
*
* Created 24 October 2006
* copyleft 2006 Tod E. Kurt <tod@todbot.com
* http://todbot.com/
Modified by Srinivasan Ramaswamy
*/
int potPin = 0; // select the input pin for the potentiometer
int speakerPin = 7;
int ledPin = 11;
int val = 0;
int PrevVal = 0;
void setup() {
pinMode(speakerPin, OUTPUT);
beginSerial(9600);
Serial.println("ready");
}
void loop() {
digitalWrite(speakerPin, LOW);
val = analogRead(potPin); // read value from the sensor
analogWrite(ledPin,val/4);
val = val*2; // process the value a little
//val = val/2; // process the value a little
for( int i=0; i<500; i++ ) { // play it for 50 cycles
digitalWrite(speakerPin, HIGH);
delayMicroseconds(val);
digitalWrite(speakerPin, LOW);
delayMicroseconds(val);
}
if (val!=PrevVal){
PrevVal = val;
}
}