/*
  Blink
  Turns on an LED on for one second, then off for one second, repeatedly.

  Most Arduinos have an on-board LED you can control. On the Uno and
  Leonardo, it is attached to digital pin 13. If you're unsure what
  pin the on-board LED is connected to on your Arduino model, check
  the documentation at http://arduino.cc

  This example code is in the public domain.

  modified 8 May 2014
  by Scott Fitzgerald

  modified 16 July 2016
  by Jody Culkin and Eric Hagan
 */

#include "pitches.h"

const int ledRed = 13;
const int speakerPin = 11;
const int buttonPin = 2;

int buttonState;

// the setup function runs once when you press reset or 
//power the board
void setup() {
    pinMode(buttonPin, INPUT);
    // initialize digital pin 13 as an output.
    pinMode(ledRed, OUTPUT);    
    buttonState = 0;
    Serial.begin(9600);
}

// the loop function runs over and over again forever
void loop() {
    buttonState = digitalRead(buttonPin);
    if (buttonState == HIGH){
        // turn the LED on (HIGH is the voltage level)
        digitalWrite(ledRed, HIGH); 
        tone(speakerPin, NOTE_A4, 500);
    }
    // turn the LED off (LOW is the voltage level)
    digitalWrite(ledRed, LOW);   
}

Leave a Reply

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