Button when pressed longer only one output

I want to get only one signal when I press a button. I'm currently building a stream deck, which is why I only need one signal, even if I press it for a long time. That's why I only need a signal when I press it once.

this is my current code for one button:

 while (digitalRead(10) == LOW) {       //Während PIN 10 aus ist dann diese Schleife ausführen
    //...F13 nutzen können
    if (digitalRead(2) == LOW) {        //Wenn Knopf von PIN 2 gedrückt dann diese Schleife ausführen
      Keyboard.press(KEY_F13);          //Tastendruck von F13-Taste simulieren
      delay (150);                      //Delay von 150ms
      Keyboard.releaseAll();            //Alle simulierten Tasten "loslassen"

The state change detection method is what you need.

The code and the comments don't fit to each other.

You should post a normal word description of the wanted functionality.

reacting on a first press and never ever reacting again until you switch off the whole device doesn't make sense.

So there must be something that is reseting the device to "act new on a short or long button-press with a single signal"

What shall this be?

a certain amount of time that has passed by?
as soon as the button is released again?

Be the change you want to see in the world
best regards Stefan

consider


#define Button  A1
#define LED     10

enum { Off = HIGH, On = LOW };

void
setup ()
{
    Serial.begin (9600);

    pinMode (Button, INPUT_PULLUP);

    digitalWrite (LED, Off);
    pinMode (LED,    OUTPUT);
}

void
loop ()
{
    static byte butState = Off;
           byte but      = digitalRead (Button);

    if (butState != but)  {
        butState = but;

        if (On == but)  {
            digitalWrite (LED, ! digitalRead (LED));

            const char *s = digitalRead (LED) ? "Off" : "On";
            Serial.println (s);
        }

        delay (10);     // debounce
    }
}

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.