int NeoPixel_2 = 6; int Drukknop1 = 8; int Drukknop1_2 = 7; int DigOutput1 = 5; #include Adafruit_NeoPixel myNeo_NeoPixel_2 = Adafruit_NeoPixel(1, 6, NEO_GRB + NEO_KHZ800); boolean Drukknop1_PRESSED = HIGH; boolean Drukknop1_2_PRESSED = HIGH; long Drukknop1buttonTimer = 0; #define Drukknop1minShortPressTime 80 #define Drukknop1longPressTime 750 boolean Drukknop1buttonActive = false; boolean Drukknop1longPressActive = false; #define Drukknop1NOPRESS 0 #define Drukknop1SHORTPRESS 1 #define Drukknop1LONGPRESS 2 int Drukknop1PressType = Drukknop1NOPRESS; long Drukknop1_2buttonTimer = 0; #define Drukknop1_2minShortPressTime 80 #define Drukknop1_2longPressTime 750 boolean Drukknop1_2buttonActive = false; boolean Drukknop1_2longPressActive = false; #define Drukknop1_2NOPRESS 0 #define Drukknop1_2SHORTPRESS 1 #define Drukknop1_2LONGPRESS 2 int Drukknop1_2PressType = Drukknop1_2NOPRESS; // Deze functie beschrijven... void opstarten() { myNeo_NeoPixel_2.setPixelColor(1-1, myNeo_NeoPixel_2.Color(255,0,0)); myNeo_NeoPixel_2.show(); delay(1000); myNeo_NeoPixel_2.setPixelColor(1-1, myNeo_NeoPixel_2.Color(255,0,0)); myNeo_NeoPixel_2.show(); delay(1000); myNeo_NeoPixel_2.setPixelColor(1-1, myNeo_NeoPixel_2.Color(255,0,0)); myNeo_NeoPixel_2.show(); } void handleDrukknop1Press() { Drukknop1PressType = Drukknop1NOPRESS; if (digitalRead(Drukknop1) == Drukknop1_PRESSED) { if (Drukknop1buttonActive == false) { Drukknop1buttonActive = true; Drukknop1buttonTimer = millis(); } if ((millis() - Drukknop1buttonTimer > Drukknop1longPressTime) && (Drukknop1longPressActive == false)) { Drukknop1longPressActive = true; Drukknop1PressType = Drukknop1LONGPRESS; } } else { if (Drukknop1buttonActive == true) { if (Drukknop1longPressActive == true) { Drukknop1longPressActive = false; } else { //avoid fast fluctuations to be identified as a click if (millis() - Drukknop1buttonTimer > Drukknop1minShortPressTime) Drukknop1PressType = Drukknop1SHORTPRESS; } Drukknop1buttonActive = false; } } } // Deze functie beschrijven... void groen() { handleDrukknop1Press(); if (Drukknop1PressType == Drukknop1SHORTPRESS) { //START STATEMENTS SHORT PRESS myNeo_NeoPixel_2.setPixelColor(1-1, myNeo_NeoPixel_2.Color(0,255,0)); myNeo_NeoPixel_2.show(); digitalWrite(5, HIGH); //END STATEMENTS SHORT PRESS } else if (Drukknop1PressType == Drukknop1LONGPRESS) { //START STATEMENTS LONG PRESS //END STATEMENTS LONG PRESS } else if (!Drukknop1longPressActive && digitalRead(Drukknop1) == Drukknop1_PRESSED) { //START STATEMENTS PRESS //END STATEMENTS PRESS } } void handleDrukknop1_2Press() { Drukknop1_2PressType = Drukknop1_2NOPRESS; if (digitalRead(Drukknop1_2) == Drukknop1_2_PRESSED) { if (Drukknop1_2buttonActive == false) { Drukknop1_2buttonActive = true; Drukknop1_2buttonTimer = millis(); } if ((millis() - Drukknop1_2buttonTimer > Drukknop1_2longPressTime) && (Drukknop1_2longPressActive == false)) { Drukknop1_2longPressActive = true; Drukknop1_2PressType = Drukknop1_2LONGPRESS; } } else { if (Drukknop1_2buttonActive == true) { if (Drukknop1_2longPressActive == true) { Drukknop1_2longPressActive = false; } else { //avoid fast fluctuations to be identified as a click if (millis() - Drukknop1_2buttonTimer > Drukknop1_2minShortPressTime) Drukknop1_2PressType = Drukknop1_2SHORTPRESS; } Drukknop1_2buttonActive = false; } } } // Deze functie beschrijven... void rood() { handleDrukknop1_2Press(); if (Drukknop1_2PressType == Drukknop1_2SHORTPRESS) { //START STATEMENTS SHORT PRESS myNeo_NeoPixel_2.setPixelColor(1-1, myNeo_NeoPixel_2.Color(255,0,0)); myNeo_NeoPixel_2.show(); digitalWrite(5, LOW); //END STATEMENTS SHORT PRESS } else if (Drukknop1_2PressType == Drukknop1_2LONGPRESS) { //START STATEMENTS LONG PRESS //END STATEMENTS LONG PRESS } else if (!Drukknop1_2longPressActive && digitalRead(Drukknop1_2) == Drukknop1_2_PRESSED) { //START STATEMENTS PRESS //END STATEMENTS PRESS } } void setup() { myNeo_NeoPixel_2.begin(); myNeo_NeoPixel_2.show(); pinMode(Drukknop1, INPUT); pinMode(Drukknop1_2, INPUT); pinMode(DigOutput1, OUTPUT); pinMode(5, OUTPUT); opstarten(); } void loop() { groen(); rood(); }