Display counter reset

Hi everybody,

I have managed to make counter which counts number of hits which are detected over piezo sensor.
Sketch is also controling stepper motor.
managed as well to start and stop stepper motor with remote control

it works ok but I can not figure out how to reset counter to zero.and I would like to use IR remote for that.

here is part of the code:

if (irrecv.decode(&results)) {
lReceived = results.value ;
Serial.println(results.value);
switch (lReceived) {
case button1:
digitalWrite(ouenable, HIGH);
Serial.println(ouenable);
break;
case button4:
digitalWrite(ouenable, LOW);
Serial.println(ouenable);
break;
case button2:
digitalWrite( HIGH, LED3);
Serial.println(LED3);
break;
case button5:
digitalWrite(LED2, LOW);
Serial.println(LED2);
break;
case button3:
digitalWrite (LED3, HIGH);
Serial.println(LED3);
break;
case button6:
digitalWrite(LED3, LOW);
Serial.println(LED3);
break;

}
irrecv.resume(); // Receive the next value
}

inpinstat = analogRead(knockSensor);
if (inpinstat >= threshold)
{
counts++;
if (counts > 9999)
{
counts = 0;
}
ten_e3 = counts / 1000;
modulo = counts % 1000;
ten_e2 = modulo / 100;
modulo = modulo % 100;
ten_e1 = modulo / 10;
modulo = modulo % 10;
ten_e0 = modulo; // "slightly unnec.", but stays w/in paradigm
digitalWrite(latchPin, LOW);
shiftOut(dataPin, clockPin, LSBFIRST, LED_SEG_TAB[ten_e0]); // LSD
shiftOut(dataPin, clockPin, LSBFIRST, LED_SEG_TAB[ten_e1]);
shiftOut(dataPin, clockPin, LSBFIRST, LED_SEG_TAB[ten_e2]);
shiftOut(dataPin, clockPin, LSBFIRST, LED_SEG_TAB[ten_e3]); // MSD
digitalWrite(latchPin, HIGH);
delay(150);
}

any ideas?

    case button7:
      counts = 0;
      break;

Hi John,

Thanks for quick reply.

Good suggestion,Rather logical too

I have tried this already... but... its not working :frowning:

Does the button7 section get executed wen you press button7?

Honestly John I do not understand question.

On serial Monitor I can see that button sends codes

and I would say no....
while using remote control to start motor after remote code there is number 10.(what ever that means)
this is not happening with button 2, just shows received signal.
Btw. I am using button 2

I would start by trying more informative messages:

 if (irrecv.decode(&results)) {
    lReceived = results.value ;
    Serial.println(lReceived);
      switch (lReceived) {

    case button1:
       digitalWrite(ouenable, HIGH);
      Serial.println(F("button1"));
      break;

    case button4:
       digitalWrite(ouenable, LOW);
       Serial.println(F("button4"));
      break;

    case button2:
      digitalWrite( HIGH, LED3);
      Serial.println(F("button2"));
      break;

    case button5:
       digitalWrite(LED2, LOW);
       Serial.println(F("button5"));
      break;

    case button3:
      digitalWrite (LED3, HIGH);
      Serial.println(F("button3"));
      break;

    case button6:
       digitalWrite(LED3, LOW);
       Serial.println(F("button6"));
      break;
    
     case button7:
       counts = 0;
       Serial.println(F("button7"));
      break;

    default:
        Serial.print(F("Received unexpected value: "));
        Serial.println(lReceived);
        break;
    }
    irrecv.resume(); // Receive the next value
  }

I did not know that this even exists :))

these are replies I got on serial monitor:

50167935
button1
-1
50151615
button2
-1
50184255
-1
50143455
button4
-1
-1

I don't know what the lines saying "-1" are from. That must be part of the sketch you have not shown yet.

The line that says "50184255" should be followed by something. Did you forget to put in the default case?

Did you push button7? It does not appear to be recognized.

Hi John

Runaway pancake jumped in mean time....
He already helped me with this code before ( ALL HAIL RANAWAY PANCAKE)

Thanks for your help.
I learned a bit from you too.