0

I am new to trying to write anything. While I can read what's happening most of the time, I have no idea how to build a delay. In Arduino I have used delays but it doesn't seem to work the same here. I have been searching the internet trying to find something that will work, but with no luck. I think I could make something work but I don't know how to add more '#includes' either. Currently I have-

#include <xbee_config.h>
#include <types.h>
#include <utils.h>
#include <xbee/atcmd.h>

I have the general idea of what is needed but now idea how to write it. I'm turning on an LED that I need delayed before turning off.

gpio_set(LED1, 1);      //Turn on LED
**Delay here!!!!**
gpio_set(LED1, 0);      //Turn off LED

My first thought is building a void_delay function that will increment a counter until x time is reached, then return to the program. I know that's not the best way as it will be keeping the program from other tasks while counting, but it should work for my purpose. The problem, I have no idea how to write that.

Mahmoud Hendi
  • 139
  • 11
  • Does this answer your question? [How do you add a timed delay to a C++ program?](https://stackoverflow.com/questions/158585/how-do-you-add-a-timed-delay-to-a-c-program) – Mahmoud Hendi Jan 10 '20 at 20:00
  • That is one that I had found, but I don’t think it is applicable. I tried the sleep() functions and kept getting sintax errors. I think the CodeWarrior platform may be different but I am not certain. It also could be that don’t have the #include (library’s?) that are noted in that post. I have not found the details of how to include more yet, but I know that has to be something in the manual I just haven’t found yet. – user12691179 Jan 11 '20 at 01:24

1 Answers1

0

In c++ you can use Sleep(milliseconds) you only have to include <windows.h>. Example:

#include <iostream>
#include <windows.h>
using namespace std;
int main() {
cout << "Before delay" <<endl;
    Sleep(5000);
cout << "After delay" <<endl;

    return 0;
}
Mahmoud Hendi
  • 139
  • 11