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 / 13052
13051  |  13053
Subject: 
Re: How2 'count' in NQC
Newsgroups: 
lugnet.robotics
Date: 
Sat, 4 Nov 2000 22:10:26 GMT
Viewed: 
675 times
  
I want to thank everyone who helped with the double problem of switch
de-bouncing and that loops can often count continuously while the switch is
in actuation.  There were good suggestions about removing delays from the
code and 'counting' upon change-of-state.  My apologies to those who find
the topic too simple.  But, for those who don't, here is the final result:

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

#define BUMPER SENSOR_2
#define LAMP OUT_B
#define FLASH_TIME 10  //a brief flash to confirm count of 5

int counter;

void check_switch()
{
    if (BUMPER == 1)//watches for actuation
    {
        until (BUMPER == 0); //checks de-actuation...
        counter += 1; //...then increments counter
    }
    if (counter == 5)
    {
        On (LAMP);
        counter = 0;
        Wait (FLASH_TIME);
        Off (LAMP);
    }
}

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

Thanks again, everyone.  This is a great newsgroup!

Jerry



Message is in Reply To:
  Re: How2 'count' in NQC
 
I have noticed this ongoing thread about the difficulties of debouncing and counting switch closures, and I must say that it is a very real problem anywhere electromechanical switches are interfaced to electronics which is orders of magnitude (...) (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