Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Feb 2005
    Posts
    18
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Delay Function for C Program

    Dear all,

    Currently, my program is using "sleep(1)" to delay the rotation of LED. This mean that it's rotating at 1 sec interval.

    Is there any delay function which i can implement so that i can rotate the LED at a faster rate??

    Thanks in advance
    west_dweller

  • #2
    Regular Coder
    Join Date
    Oct 2004
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    You probably want to use usleep(microseconds)

  • #3
    Regular Coder
    Join Date
    May 2004
    Location
    New Hampshire, America
    Posts
    246
    Thanks
    0
    Thanked 2 Times in 2 Posts
    In C Programming both Sleep(), sleep(), and SleepEx() all pause for milliseconds. Not seconds. So your code should be working fine unless I missed something.

    ~dunna

  • #4
    Regular Coder
    Join Date
    Oct 2004
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Sleep() and SleepEx() are windows functions which wait for milliseconds, while sleep() is a linux function which waits for seconds.

    Since he used sleep() in his example and not Sleep(), I gave him a linux function he can use to get a lower wait time than 1 second.

  • #5
    Regular Coder
    Join Date
    May 2004
    Location
    New Hampshire, America
    Posts
    246
    Thanks
    0
    Thanked 2 Times in 2 Posts
    Sorry to mislead you West_dweller79.....

    For some reason sleep() does not work in m projects. VC++ 6.0 on WinXP SP1. It shows up in MSDN but I don't see any libraries or headers to include to work it.

  • #6
    Regular Coder
    Join Date
    Oct 2004
    Posts
    230
    Thanks
    0
    Thanked 0 Times in 0 Posts
    For windows sleep() is undefined, as I posted earlier it's used in alot of linux distributions.

    You should #include <windows.h> and use Sleep(ms).

    An alternative would be to #include <stdlib.h> and use _sleep(ms) if it's available for your compiler.


    .


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •