Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

C language loop question

Options
  • 28-02-2006 8:08am
    #1
    Registered Users Posts: 2,164 ✭✭✭


    I have a function call "Start" for a start button (physical button) and another function call "Stop" for a stop button (physical button also)..

    I need to create a loop that keep on running "Start" once I pressed it until the stop button is pressed which then it must use the "stop" function..

    My problem is how do I implement the stop function?
    Bcoz to implement it that means I have to manually enter a line into the loop to call the function.. I'm outta ideas..

    Anyone? Any help appreciated.. thanks in advance

    West Dublin, ☀️ 7.83kWp ⚡5.66 kWp South West, ⚡2.18 kWp North East



Comments

  • Registered Users Posts: 1,275 ✭✭✭bpmurray


    Set a boolean when you press Stop, and check it during your general loop. Something like:
    unsigned short StopPressed = 0;
    
    void MainLoop() {
        while (!StopPressed) {
            doStuff();
            doMoreStuff();
            etc();
        }
        doStopStuff();
    }
    
    void StopButtonPressFunction() {
       StopPressed = 1;
    }
    


Advertisement