const int ledPin = 9;
const int buttonPin1 = 12; // Increment Button
const int buttonPin2 = 13; // Decrement Button
int lastState1 = HIGH; // the previous state from the input pin
int lastState2 = HIGH;
int pushCounter = 0; // counter for the number of button presses
int currentState1, currentState2; // the current reading from the input pin
int fadeValue = 0;
void setup() {
pinMode(ledPin, OUTPUT);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
}
void loop() {
currentState1 = digitalRead(buttonPin1);
currentState2 = digitalRead(buttonPin2);
if (currentState1 != lastState1) {
if (currentState1 == LOW) {
pushCounter++;
fadeValue = pushCounter * 32;
}
}
lastState1 = currentState1;
if (currentState2 != lastState2) {
if (currentState2 == LOW) {
pushCounter--;
fadeValue = pushCounter * 32;
}
}
lastState2 = currentState2;
analogWrite(ledPin, fadeValue);
if (pushCounter >= 8) {
pushCounter = 0;
}
delay(50);
}