// constants won't change. They're used here to
// set pin numbers:
const int buttonPin1 = 2;     // the number of the pushbutton pin
const int buttonPin2 = 3;     // the number of the pushbutton pin
const int buttonPin3 = 4;     // the number of the pushbutton pin

const int speakerPin = 11;    //the number of the speaker pin

const int ledPin = 13;       //the number of the LED pin

// variables will change:
int buttonState1 = 0;         // variable for reading the pushbutton status
int buttonState2 = 0;         // variable for reading the pushbutton status
int buttonState3 = 0;         // variable for reading the pushbutton status

void setup() {
  // initialize the pushbutton pins as inputa:
  pinMode(buttonPin1, INPUT);
  pinMode(buttonPin2, INPUT);
  pinMode(buttonPin3, INPUT);

  // initialize the LED pin and the Speaker pin as an output:
  pinMode(speakerPin, OUTPUT);
  pinMode(ledPin, OUTPUT);
}

void loop() {
  // read the state of the pushbutton value:
  buttonState1 = digitalRead(buttonPin1);
  buttonState2 = digitalRead(buttonPin2);
  buttonState3 = digitalRead(buttonPin3);
  
  // check if the pushbutton is pressed.  
  if (buttonState1 == HIGH) {
    digitalWrite(ledPin, HIGH);
    tone (speakerPin, 329.63);
  }

  else if (buttonState2 == HIGH) {
    digitalWrite(ledPin, HIGH);  
    tone (speakerPin, 293.66);
  }

  else if (buttonState3 == HIGH) {  
    digitalWrite(ledPin, HIGH);
    tone (speakerPin, 261.63); 
  }

  else {
    // turn LED off:
    noTone(11);
    digitalWrite(ledPin, LOW);
  }
}

Leave a Reply

Your email address will not be published. Required fields are marked *

You may use these HTML tags and attributes:

<a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong>