// Define the pin number for the push button
const int buttonPin1 = 8;
const int buttonPin2 = 9;
const int ledPin = 10;
const int buzzPin = 11;
int buttonState1 = LOW;
int buttonState2 = LOW;
int brightness = 0;
int fadeAmount = 25;
int dt = 100;
// Setup function runs once when the program starts
void setup() {
// Set the button pin as an input with an internal pull-up resistor
pinMode(buttonPin1, INPUT_PULLUP);
pinMode(buttonPin2, INPUT_PULLUP);
pinMode(ledPin, OUTPUT);
pinMode(buzzPin, OUTPUT);
// Start the serial monitor at 9600 baud
Serial.begin(9600);
}
// The loop function runs repeatedly after setup()
void loop() {
// Read the current state of the button (HIGH or LOW)
buttonState1 = digitalRead(buttonPin1);
buttonState2 = digitalRead(buttonPin2);
Serial.print(" Button 1 = ");
Serial.println(buttonState1);
Serial.print(" Button 2 = ");
Serial.println(buttonState2);
delay(dt);
// Check if the button1 is currently pressed (LOW)
if (buttonState1 == LOW) {
brightness += fadeAmount;
if(brightness > 255)
{
brightness = 255;
digitalWrite(buzzPin, HIGH);
delay(dt);
digitalWrite(buzzPin, LOW);
//tone(buzzPin,1000,100);
Serial.println("WARNING: Maximum Intensity of LED");
}
}
// Check if the button2 is currently pressed (LOW)
if (buttonState2 == LOW) {
brightness -= fadeAmount;
if(brightness < 0)
{
brightness = 0;
digitalWrite(buzzPin, HIGH);
delay(dt);
digitalWrite(buzzPin, LOW);
Serial.println("WARNING: MINIMUM Intensity of LED");
}
}
Serial.print("Brightness :- ");
Serial.println(brightness);
analogWrite(ledPin, brightness);
}