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 / 13029
13028  |  13030
Subject: 
How2 'count' in NQC
Newsgroups: 
lugnet.robotics
Date: 
Thu, 2 Nov 2000 23:03:23 GMT
Viewed: 
554 times
  
In NQC you count by adding 1 to a variable like this:

int counter;
counter += 1

But it's hard to know *how much* you have counted;  however, you can build a
little program to (say) flash a light when you reach a certain count.

I have spent about 4 hours discovering that a touch sensor can count many
times where you expect it to count *once*.  So, does anyone out there know
how to count once only for each switch actuation, but in simpler form than
the following (which does work to count only once within a delay of 50 ticks.

//Bug6Leg4.nqc
//program to check results of a counter

#define BUMPER SENSOR_2
#define LAMP OUT_B
#define FLASH_TIME 10
#define DELAY 50

int counter;

void check_switch()
{
    if (BUMPER == 1)
    {
        counter += 1;
        Wait (DELAY); //to register 1 count only
    }
}

void check_counter()
{
    if (counter > 5) //light flashes after the 6th actuation
    {
        On (LAMP);
        counter = 0;
        Wait (FLASH_TIME);
        Off (LAMP);
    }
}

task main()
{
    counter = 0;
    SetSensor (BUMPER, SENSOR_TOUCH);
    while (true)
    {
        check_counter();
        check_switch();
    }
}

Thanks in advance for your help.



Message has 1 Reply:
  Re: How2 'count' in NQC
 
(...) The sensor returns 1 for as long as it's held down. In your code: (...) You are actually counting how long the switch is held down - in units of about a half second. So if you press and hold the switch for ten seconds, you'll get a count of (...) (24 years ago, 3-Nov-00, to lugnet.robotics)

6 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