//unfinsihed
//31 Hz to 65535 Hz
#include <MusicBuzzer.h>
const int BUZZER_PIN = 9; // declaring the PWM pin
const int BUTTON_PIN = 2; // declaring button pin
int oldValue = LOW; // default/idle value for pin 8 is low.
void setup() {
// put your setup code here, to run once:
Serial.begin(8600);
Serial.println("The button is pressed.");
//pinMode(BUZZER_PIN, OUTPUT); //addigning pin to Output mode
music.init(BUZZER_PIN);
pinMode(BUTTON_PIN, INPUT);
}
void loop() {
//RunMusicSound();
ButtonPressed();
}
void RunBuzzerSound(){
// put your main code here, to run repeatedly:
tone(BUZZER_PIN, 4000); // Send 1KHz sound signal...
delay(1000); //pause...for 1 sec
noTone(BUZZER_PIN); //// Stop sound...
//delay(1000); //// ...for 1sec
tone(BUZZER_PIN, 1000); // Send 1KHz sound signal...
delay(1000); //pause...for 1 sec
noTone(BUZZER_PIN); //// Stop sound...
delay(100); //// ...for 1ms
}
void RunMusicSound()
{
music.takeonme(); //YOU'VE BEEN RICK ROLLED
delay(2000);
}
void ButtonPressed()
{
// Read the value of pin 8.
int newValue = digitalRead(BUTTON_PIN);
// Check if the value was changed,
// by comparing it with the previous value.
if(newValue != oldValue)
{
if(newValue == HIGH)
{
Serial.println("The button is pressed.");
RunMusicSound();
}
else
{
Serial.println("The button is released.");
noTone(BUZZER_PIN); //// Stop sound...
}
// Remember the value for the next time.
oldValue = newValue;
}
// Slow down the sketch.
// Also for debouncing the button.
delay(100);
}