|
-
Jun 10th, 2001, 12:51 AM
#1
Thread Starter
PowerPoster
Again, that double For loop
I am creating a stepper motor controller which has a stepper motor and a LED.
-- When the stepper motor moves, I want to flash the led. To flash the LED, I need to first send a "1" and then a delay of some second, and then a "0".
-- When the motor is moving -- it is in a loop -- I want to flash the led.
--I have created a function for the delay that looks like this
code:--------------------------------------------------------------------------------
For delaytime = 1 to 40000
Next
--------------------------------------------------------------------------------
--Now If I put this code:
code:--------------------------------------------------------------------------------
Do
(Here is all the code to rotate the motor in a loop which is too long so I did not put it here)
portn = PortIn(888)
Call PortOut(888, portn + 16)
delay
Call PortOut(888, portn + 0)
delay
Loop
--------------------------------------------------------------------------------
(PortOut, PortIn are just two functions to send and retrieve a value to and from the parallel port. "16" is just the value which lights the led, and 0 turns the led off. I retrived the value from the parallel port first because I wanted the motor to keep rotating)
The problem is that when the delay is used, it stop the led flashing and also the stepper motor. I want the stepper motor to keep doing its work but the led should stop for the time which is given the loop.
If you dont understand anything then please ask me
-
Jun 10th, 2001, 01:00 AM
#2
Hyperactive Member
I don't really understand the complexities of the I/O here, but you could try putting a DoEvents in the middle of the delay loop.
(As an aside, if you want to make your code more general and compatible with different speeds of processor you could use the timer function in the loop)
Code:
private sub Delay
dim lTimer as long
lTimer=timer
while timer<ltimer+1
doevents
wend
end sub
I hope this helps,
SD
"I'd rather have a full bottle in front of me than a full frontal lobotomy!"
-
Jun 10th, 2001, 12:20 PM
#3
Hyperactive Member
Firstly, I should apologise and point out that my previous code is wrong and ltimer should have been dTimer and defined as double,
apart from that let me see if I can get this straight.
You increment the stepper motor continuosly and flash the led at the same time (with intervals of a second).
To do this I would put a timer on the form (let's call it timer1). Leave it with an .interval property of 1000 (1 second). Then put the following code into the timer event
Code:
static bLEDOn as boolean
bLEDOn=not bLEDOn '// This toggles the value between true and false each time the timer is fired
if bLEDOn = true then
Call PortOut(888, portn + 16)
else
Call PortOut(888, portn + 0)
end if
timer1.enabled=true
when you wish to start the LED flashing use the line
Code:
timer1.enabled = true
When you wish to stop it flashing use
Code:
timer1.enabled=false
This way you don't need to use the delay function, but can continue to step the stepper motor and the timer event should take care of the LED flashing.
So you would end up with
Code:
Do
Timer1.enabled=true '// Start LED flashing
DriveCar
Loop Until Car.Fuel = 0
Timer1.enabled=false '// Stop LED from flashing
I think I understand what you want. Hopefully this will help,
SD
"I'd rather have a full bottle in front of me than a full frontal lobotomy!"
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|