To LUGNET HomepageTo LUGNET News HomepageTo LUGNET Guide Homepage
 Help on Searching
 
Post new message to lugnet.robotics.rcx.nqcOpen lugnet.robotics.rcx.nqc in your NNTP NewsreaderTo LUGNET News Traffic PageSign In (Members)
 Robotics / RCX / NQC / 1225
1224  |  1226
Subject: 
Re: monitoring touch sensor
Newsgroups: 
lugnet.robotics.rcx.nqc
Date: 
Sat, 15 Sep 2001 03:39:25 GMT
Viewed: 
2540 times
  
In lugnet.robotics.rcx.nqc, Jason Yee writes:
I would like to monitor a touch sensor (with a Scout) so that if the sensor
is pressed once and held down a motor runs forward.  If the touch sensor is
pressed twice within a given time (eg. 2 seconds) and held down than the
motor runs in reverse.  What would be a good way to do this?

Please keep in mind the Scout does not support Pulse or Edge modes.


FYI, Jason and I ended up with this program:

int touch_count=0;
int release_count=0;

task main() {
  while (true) {  // infinite loop
    // look for first press
    until(SENSOR_1 == 1);
    PlaySound(SOUND_CLICK);
    touch_count = 1;

    // wait for 1 second for a possible release
    monitor(EVENT_1_RELEASED) {
      Wait(100);
    }
    catch {
      PlaySound(SOUND_DOUBLE_BEEP);
      release_count = 1;
    }

    // wait for second press, or continuation of 1st press
    monitor(EVENT_1_PRESSED) {
      Wait(100);
    }
    catch {
      if(release_count) {
        touch_count = 2;
        PlaySound(SOUND_CLICK);
      }
    }

    if(touch_count == 1) {
      // move forward
      OnFwd (OUT_A);
    } // else
    if(touch_count == 2) {
      OnRev (OUT_A);
    }

    until(SENSOR_1 == 0); // wait until stop pressing
    Off(OUT_A);
  }
}



Message is in Reply To:
  monitoring touch sensor
 
Greetings I have recently been learning to program in NQC and have run into a problem. I would like to monitor a touch sensor (with a Scout) so that if the sensor is pressed once and held down a motor runs forward. If the touch sensor is pressed (...) (23 years ago, 31-Aug-01, to lugnet.robotics.rcx.nqc)

2 Messages 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