hello everyone
if anyone is willing to help me, I really appreciate it
I'm having problems here, because I'm still learning, just learning Arduino as long as there is fukg Virus #stay at home
this is blink 3x my problem is a bug on the buttonState if you switch several times, the start of the led should be off but this is high ......... and how to add int, for example: led blink 2x for 3 times and led blink 3x for 3 times continuously
and this is my code:
const byte LedPin = 13;
long currentTime;
const int pinPot = A0;
int sensor = 0;
int buttonState = 0;
const int buttonPin = 2;
void setup()
{
pinMode(LED_BUILTIN, OUTPUT);
pinMode(buttonPin, INPUT);
digitalWrite(13, LOW);
#define INTERVAL 5L
#define BLINK_TIMES 3
#define BLINK_TIMES_1 2
}
void loop()
{
buttonState = digitalRead(buttonPin);
if (buttonState == HIGH) {
digitalWrite(13, LOW);}
else{
sensor = map(analogRead(pinPot), 0, 1023, 500, 5);
static unsigned long lastBlink = 0;
static int count = 0;
unsigned long now = millis();
if(count > 0) {
count -= blink();
lastBlink = now;
} else {
if(now - lastBlink >= INTERVAL*sensor) {
count = BLINK_TIMES;
}
}
}
}
int blink()
{ static unsigned long lastFlip = 0;
static int count = 0;
bool last = false;
unsigned long now = millis();
if(now - lastFlip >= sensor) {
digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
lastFlip = now;
count++;
if (count == 2) {
count = 0;
last = true;
}
}
return (last) ? 1 : 0 ;
}
thank you for replying. 8)