Simple piano

i am trying to create a simple piano. Maybe six keys or so. I have never used a speaker before and am quite confused with trying to write a code. Could someone point me in a direction that would help me out, or show me how to write a code for one note to continuously play. If someone could show me that I think I could do the rest considering most of it is just switches to toggle on and off for the note.

Does any of this help...

http://www.arduino.cc/cgi-bin/yabb2/YaBB.pl?num=1257390337

not really that code does not work and I have no idea what is wrong with it

This should help:

I would then switch case code for what tone to play:
http://www.arduino.cc/en/Reference/SwitchCase

Hope that helps, :wink:

Mowcius

I guess thins is what i want, but I am guessing that there is a "tone library" that i need to download. How would I go about doing so and installing it.
PS I am working with a mac.

#include <Tone.h>

#define SPEAKER 9
#define BUTTON 4

Tone tone1;

int buttonState = 0; //store value of button pin

void setup()
{
  pinMode(BUTTON, INPUT);
  tone1.begin(SPEAKER);
}

void loop()
{
  buttonState = digitalRead(BUTTON);
  if (buttonState == HIGH)
  {
    // play a tone, then wait for a bit before checking the button again
    tone1.play(NOTE_A4);
    delay(500);  // 500 = 500 ms or 1/2 second
    tone1.stop();
  }
}

I think that this is what you are looking for then:
http://code.google.com/p/arduino-tone/

Before installing your first library, you'll need to create the libraries directory. Then, simply unzip the library into it. When you restart Arduino, the library should appear in the Sketch > Import Library menu. Any examples for the library should show up in the Files > Examples menu.

I have not used the arduino IDE on a mac but this is apparently what you need to do :smiley:

Mowcius