unsigned long Delay = 1000;
unsigned long lastmillis;
unsigned long currentMillis;
const int Ledpins[] = {2,3};
bool bright = false;
int ledState = LOW;
bool Buzzer = false;
unsigned int fadestate = 1;
void setup() {
Serial.begin(9600);
Serial.println("Enter Number For Function");
Serial.println("1) Turn On Buzzer");
Serial.println("2) Increase LED blinking speed");
Serial.println("3) Decrease LED blinking speed");
Serial.println("4) Toggle LED brightness");
}
void loop() {
UserIn();
Blink();
Fade();
// put your main code here, to run repeatedly:
}
void UserIn(){
if (Serial.available()>0){
int selection = Serial.read();
switch(selection){
case '1':
Buzz();
break;
case '2':
Delay = Delay - 100;
Serial.println("Increasing Blink Speed");
break;
case '3':
Delay = Delay + 100;
Serial.println("Decreasing Blink Speed");
break;
case '4':
fadestate = fadestate + 1;
if (fadestate > 2){
fadestate = 1;
}
Serial.println(fadestate);
digitalWrite(3, HIGH);
break;
}
}
}
void Blink(){
unsigned long currentMillis = millis();
if (currentMillis - lastmillis >= Delay){
lastmillis = currentMillis;
if (ledState == LOW)
ledState = HIGH;
else {
ledState = LOW;
}
digitalWrite(Ledpins[0],ledState);
}
}
void Buzz(){
if (Buzzer = true){
tone(8, 262);
}
}
void Fade(){
switch(fadestate){
case 1:
analogWrite(3, 255);
break;
case 2:
analogWrite(3, 20);
break;
}
}