|
|
|
![]() |
|
|||||||
|
||||||||
![]() |
| Thread Tools | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hello!
I'm searching after the delay command (or the equivalent) in C. I'm sorry if it has been asked before but I hadn't found what I need with the "search"). Thanks allot, Ben Barchechath. ![]() |
|
#2
|
|||||
|
|||||
|
Re: Commands
EasyC has a "Wait" function, however, the MPLAB C version default code cannot accommodate a lengthly delay. Any substantial delay in that version causes the processor to be disabled.
If you have a specific need we can suggest typical alternatives. |
|
#3
|
|||
|
|||
|
Re: Commands
We are using the same switch of the joystick to do two jobs.
I some need kind of delay because when i press the button once the robot doing the open and close command too fast. And that is why i am searching for a delay of something like two seconds. P.S. I'm using the MPLAB. Thanks. |
|
#4
|
||||
|
||||
|
Re: Commands
What is it that you're actually trying to do? There's no "wait" command but if you describe what you're trying to do, perhaps we can find an alternative way to do what you want.
|
|
#5
|
|||||
|
|||||
|
Re: Commands
Quote:
1) You can program the joystick button to act one way when you hold it down and do the opposite when you let it go. For instance, close when you hold the button and open only when you release the button. 2) You can program the button to toggle so you have to push it and let go each time you want it to do something. For instance, push once and let go for close, then push once again to open. Either of these fit what you are trying to do? Last edited by Mark McLeod : 05-02-2007 at 15:40. |
|
#6
|
|||
|
|||
|
Re: Commands
There are two different types of delays: blocking and non blocking. A blocking delay halts execution of EVERYTHING for that amount of time. A non-blocking delay only affects a small portion of the code.
I believe you are looking for a non-blocking delay. I would suggest adding a counter to your code that increments at the top of the control loop. Code:
time_counter+=1;
if(button_pressed && time_counter>desired_delay)
do stuff;
time_counter=0;
rest of code
If you are looking for a blocking delay, you have several options, two of which I have outlined below. The simple (read "simple"" as "bad") way is to simply spin in a loop. Code:
for(i=0;i<DELAY_TIME;i++); I am guessing that this means that there is a watchdog that is timing out. If you really want to, you could delay, pet the watchdog, delay some more, pet him again, delay more, etc. When you get to this point, you are probably doing something wrong. |
|
#7
|
|||||
|
|||||
|
Re: Commands
Quote:
A two second delay would be way too long. |
|
#8
|
|||||
|
|||||
|
Re: Commands
Quote:
If that doesn't sound like what you need, please give some more detail about what you want the button to do. |
![]() |
| Thread Tools | |
| Display Modes | Rate This Thread |
|
|
Similar Threads
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Relay Commands | Matt Krass | Programming | 6 | 18-02-2006 23:03 |
| Serial Commands on MPLAB | tribotec_ca88 | Programming | 2 | 24-01-2006 16:26 |
| at commands in c++ | daroch | Programming | 1 | 04-03-2005 01:01 |
| Kevin's Commands.h?? | kshot | Programming | 3 | 17-02-2005 17:12 |
| Voice Activated commands | Amber H. | Technical Discussion | 40 | 03-11-2002 12:40 |