Subject:
|
Re: How2 'count' in NQC
|
Newsgroups:
|
lugnet.robotics
|
Date:
|
Fri, 3 Nov 2000 17:05:52 GMT
|
Viewed:
|
636 times
|
| |
| |
Steve, this is the third time you have helped me, and this time you
obviously spent a lot of time working out the alternatives. First of all,
the Wait (DELAY); in my inept code was not to flash every half second. It
was to prevent additional counts to be registered during that half second.
It does that. What bothers me is that I think there must be a way to
de-bounce a switch (1 count per actuation) without 15 or 20 statements. I
have found 'clues' throughout Dave Baum's Definitive Guide. For example, on
pages 126 and 127 he uses a counter to add 'bumps' and get his bugbot out of
a corner when the count exceeds a limit. I know his code works, but I'm not
sure why. It took real research on my part to discover that the counter
...keeps counting... as long as the switch is held down (perhaps at
clock-speed - delays).
Thanks again, and I will be going through your *reply* with a fine-tooth comb!
Jerry
> In your code:
>
> > #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
> > }
> > }
>
> 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 about 20 in 'counter.
|
|
Message has 1 Reply: | | Re: How2 'count' in NQC
|
| In lugnet.robotics, Jerry Kalpin writes: [SNIP] (...) There is an EDGE mode available through the firmware that only counts transitions between pressed and non-pressed (actually some raw threshold value if I remember correctly) states. This sensor (...) (24 years ago, 3-Nov-00, to lugnet.robotics)
|
Message is in Reply To:
| | 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
This Message and its Replies on One Page:
- Nested:
All | Brief | Compact | Dots
Linear:
All | Brief | Compact
|
|
|
|