Counter

25 May 2010

Hi i am making a program with a counter, i was wondering how you can reset it

25 May 2010
Sorry, your question is not clear. Can you provide more details? What kind of counter do you have in mind, and what would the resetting do?
25 May 2010

sorry about not being clear what I am trying to measure RPM using a QRD1114 and I can get record how many times the axle goes round but i need the count to reset to 0 every second so i can work out the RPM this is my program:

#include "mbed.h"
#include "TextLCD.h"

class Counter {
public:
    Counter(PinName p18) : _interrupt(p18) {       
        _interrupt.rise(this, &Counter::increment);
    }

    void increment() {
        _count++;
    }

    int read() {
        return _count;
count_reset
    }

private:
    InterruptIn _interrupt;
    volatile int _count;
  
};

Counter counter(p18);

int main() {
    TextLCD lcd(p24, p25, p26, p27, p28, p29, p30); // rs, rw, e, d0, d1, d2, d3
    while(1) {
        lcd.printf("Count so far:\n %d\n", counter.read());
       
       
    }
}

25 May 2010

the "count_reset" is not ment to be in it.

25 May 2010
Add a Ticker which would call counter.reset every second. In reset() you can e.g. calculate current RPM, store it, and reset _count to 0.
26 May 2010

Thanks for your help.