I think you didn't understand me. I want the led diode to blink as many times as the number shown on my display, that is, if the display says 100, I have to press some button to confirm and the crazy diode starts to blink 100 times!
He did understand you. But then he read your code and realised there were so many mistakes that needed to be corrected before any additional feature was added.
You seem to have some { } randomly placed throughout your code that serve no purpose... other than to confuse. (2 sets).
So you have 2 buttons... 1 to count up, 1 to count down? Suggestion... call the variables associated with up - upButton, upState, UpPrevious... and have a similar set for down. Currently up & down seem to be sharing lastButtonState... and you never update lastButtonState.
You don't need to delay(100). Serves no purpose other than block your code.
OK.. so now for the blinking.
You need to decide how this is going to work. While blinking are the buttons ignored? How quickly should the LED blink? Is there a 3rd button that triggers (confirms) the blinking)
yes, I need to add another button for the confirmation. yes, the buttons are ignored while the LED is flashing and it doesn't matter how fast. for the unnecessary {}, I am new and I take some codes from the internet, I redo them and these {} remain there
Here's an example. The code for the new button is the same as the others. Once pressed it simply loops turning the LED on and off. It uses delay() for the timing, which is OK in this case, but if you want to do other things while the LED is flashing you need a different approach.
Untested.
#include <TM1637Display.h>
#define CLK 3
#define DIO 4
int upPin = A0;
int upState = 0;
int upPrevious = LOW;
int downPin = A1;
int downState = 0;
int downPrevious = LOW;
int confirmPin = A2;
int confirmState = 0;
int confirmPrevious = LOW;
int ledPin = 2;
int buttonCounter = 0;
TM1637Display display = TM1637Display(CLK, DIO);
const uint8_t allON[] = {0xff, 0xff, 0xff, 0xff};
const uint8_t allOFF[] = {0x00, 0x00, 0x00, 0x00};
void setup()
{
pinMode(upPin, INPUT);
pinMode(downPin, INPUT);
pinMode(confirmPin, INPUT);
pinMode(ledPin, OUTPUT);
display.setBrightness(5);
}
void loop()
{
// Check the "Up" button.
upState = digitalRead(upPin);
if (upState != upPrevious)
{
if (upState == HIGH)
buttonCounter++;
upPrevious = upState;
}
// Check the "Down" button.
downState = digitalRead(downPin);
if (downState != downPrevious)
{
if (downState == HIGH)
buttonCounter--;
downPrevious = downState;
}
// Display the counter on the screen.
display.showNumberDec(buttonCounter);
// Check the "Confirm" button. If pressed then flash the LED.
confirmState = digitalRead(confirmPin);
if (confirmState != confirmPrevious)
{
if (confirmState == HIGH)
{
for (uint8_t x = 0; x < buttonCounter; x++)
{
digitalWrite(ledPin, HIGH);
delay(300);
digitalWrite(ledPin, LOW);
delay(300);
}
}
confirmPrevious = confirmState;
}
}