Piezo Game Board

Posted by dperry

dperry's picture

Description:
I used wanted to create a musical game board that emitted sounds as players moved across the board. You can see the video: http://www.youtube.com/watch?v=Ai90Gg9lIko

Materials Used:

  • Piezo speaker
  • FSR sensor
  • 10kohm resistor
  • Game Board
  • Game Piece

Code Used:

 *
 * Created 24 October 2006
 * copyleft 2006 Tod E. Kurt <tod@todbot.com
 * http://todbot.com/
 */

int potPin = 0;    // select the input pin for the sensor
int speakerPin = 7; // input pin for the piezo

int val = 0;

void setup() {
  pinMode(speakerPin, OUTPUT);
  Serial.begin(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<50; i++ ) {  // play it for 50 cycles
    digitalWrite(speakerPin, HIGH);
    delayMicroseconds(val);
    digitalWrite(speakerPin, LOW);
    delayMicroseconds(val);
  }
}

0
Your rating: None