To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.roboticsOpen lugnet.robotics in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / 17920
17919  |  17921
Subject: 
Re: nqc question
Newsgroups: 
lugnet.robotics
Date: 
Thu, 16 May 2002 20:52:43 GMT
Original-From: 
Stephen J Baker <[sjbaker@]NoMoreSpam[link.com]>
Reply-To: 
<SJBAKER@avoidspamLINK.COM>
Viewed: 
825 times
  
I want to have a motor turn as long as i press a touch sensor and
stop when i release it.
This is probly a very simple problem but I cant seem to solve it.
I tried if while and until but for some reason it didn't work

while(1)
{
if(SENSOR_X == 1)
   On(OUT_Y);
until(SENSOR_X == 0)
}

I don't see how that could possibly work - where does this code turn
the motor off?

You need something like:

task sensor_to_motor ()
{
  while ( 1 )  /* Do this forever... */
  {
    Off ( motor ) ;  /* Turn the motor off */

    while ( sensor == 0 )  /* Wait until the button is pressed */
      /* Do Nothing */ ;

    OnFwd ( motor ) ;  /* Turn the motor on */

    while ( sensor == 1 )  /* Wait until the button is released */
      /* Do Nothing */ ;
  }
}

Change 'motor' and 'sensor' to whichever OUT_ and SENSOR_ you
need - start the task running from 'main'.  If you are using
the RCX to do something else at the same time then you should
probably save some CPU time by replacing the two ocurrances
of '/* Do Nothing */' with short duration 'Wait()' commands.

----
Steve Baker                      (817)619-2657 (Vox/Vox-Mail)
L3Com/Link Simulation & Training (817)619-2466 (Fax)
Work: sjbaker@link.com           http://www.link.com
Home: sjbaker1@airmail.net       http://www.sjbaker.org



1 Message in This Thread:

Entire Thread on One Page:
Nested:  All | Brief | Compact | Dots
Linear:  All | Brief | Compact
    

Custom Search

©2005 LUGNET. All rights reserved. - hosted by steinbruch.info GbR