Maybe a bit of a boring answer, but as there this code has many ifs, elses and elseifs: Have you tried using serial.println to figure out what blocks are being ran and which arent?
My guiss is that if you know the order things are run in, you’ll know if it behaves as you intended when programming. If conditions you assume to be true, actually are true, etc.
// Mygtuko kontaktas
const int buttonPin = 7;
// LED kontaktai
const int LED1 = 13;
const int LED2 = 12;
unsigned long previousMillis = 0;
const long interval = 300;
int LED1Status = LOW;
int LED2Status = LOW;
int buttonState;
unsigned long timePress = 0;
unsigned long timePressLimit = 0;
int clicks = 0;
void setup() {
pinMode(buttonPin ,INPUT_PULLUP);
pinMode(LED1, OUTPUT);
pinMode(LED2, OUTPUT);
Serial.begin(9600);
}
void loop() {
unsigned long currentMillis = millis();
buttonState = digitalRead(buttonPin);
if (buttonState == LOW){
delay(200);
//Serial.println("Paspaustas");
if (clicks == 0) {
timePress = millis();
timePressLimit = timePress + 1000;
clicks = 1;
}
else if (clicks == 1 && millis() < timePressLimit){
//Serial.println("Paspaustas du kart");
//Double click veiksmas
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (LED2Status == LOW) {
LED2Status = HIGH;
} else {
LED2Status = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(LED2, LED2Status);
}
timePress = 0;
timePressLimit = 0;
clicks = 0;
}
}
if (clicks == 1 && timePressLimit != 0 && millis() > timePressLimit){
//Serial.println("Viena karta paspaustas");
timePress = 0;
timePressLimit = 0;
clicks = 0;
//One click veiksmas
if (currentMillis - previousMillis >= interval) {
// save the last time you blinked the LED
previousMillis = currentMillis;
// if the LED is off turn it on and vice-versa:
if (LED1Status == LOW) {
LED1Status = HIGH;
} else {
LED1Status = LOW;
}
// set the LED with the ledState of the variable:
digitalWrite(LED1, LED1Status);
}
}
}
this is my first project with arduino, so please be patient :))