#include <Arduino.h>
#include <stdio.h>
//#include <NewToneLib.h>
const int button_1 = 5; // turns led_1 on and off , pin 1 and 0 default to high
const int button_2 = 2;// slows blinking of led_2
const int button_3 = 3; // speeds blinking of led_3
const int button_4 = 4;
const int led_1 = 13; //on/off led
const int led_2 = 11; // led that will blink
const int buzzer = 12; // buzzer
//MyTone t(false);
void setup() {
pinMode(button_1,INPUT); // configure each pin 1,2,3,4 to be an input.
pinMode(button_2,INPUT);
pinMode(button_3,INPUT);
pinMode(button_4,INPUT);
pinMode(buzzer, OUTPUT); //pin 13 as output
pinMode(led_1,OUTPUT); // initilize d13 as the output
pinMode(led_2,OUTPUT);
Serial.begin(9600);
}
void led_2_control() { //pin 11
if (digitalRead(button_2)==HIGH){
slow_blink(led_2);
}
else if (digitalRead(button_3)==HIGH) {
fast_blink(led_2);
}
else {
blink(led_2); // 1s blink as default
}
}
void fast_blink(int led) {
digitalWrite(led, HIGH);
delay(200); // waits for a second
digitalWrite(led, LOW);
delay(200); // waits for a second
}
void slow_blink(int led){
digitalWrite(led, HIGH);
delay(3000); // waits for ~3 second
digitalWrite(led, LOW);
delay(3000); // waits for ~3 second
}
void blink(int led) {
digitalWrite(led, HIGH);
delay(1000); // waits for a second
digitalWrite(led, LOW);
delay(1000); // waits for a second
}
void led_1_onoff(){
if (digitalRead(button_1) == HIGH){
digitalWrite(led_1, HIGH);
}
if (digitalRead(button_1) == LOW){
digitalWrite(led_1, LOW);
}
}
void buzzer_control(){
//digitalWrite(buzzer,HIGH);
if (digitalRead(button_4)== HIGH){
tone(buzzer, 1500, 0);
}
else{
tone(buzzer, 600, 0);
}
}
//int notei[] = {262, 294, 330, 349, 392, 440, 494, 523};
// int durationi[] = {500, 500, 500, 500, 500, 500, 500, 500};
// for(int i = 8; i <=8; i++){
// int note = notei[i];
//int note_length = durationi[i];
//tone(buzzer, note, note_length);
//delay(note_length);
//}
void loop() {
led_1_onoff();
led_2_control();
buzzer_control();
}