Counter code issue

Hi,

I am creating code and hardware for a college product, which displays a waiting time in a queuing system. It counts the amount of people going through a gate. Once six people have passed through the gate, the waiting time goes up by one minute.

To the issue; I understand why it is happening, I just don't know how to resolve the problem. Once the "reedCounter" gets to 6, the "minuteCounter" does go up, but it doesn't stop going up until the "reedCounter" is incremented again.

Here is some code;

 if(reedCounter % 6 == 0) {
   minuteCounter++; 
   lcd.setCursor(10,0);
   lcd.print(minuteCounter); 
}

Thanks very much in advance.
Marcus.

Here is some code;

Here is some answer:
Clearly, you need to

When you post ALL of your code, I'l post all of the answer.

It would appear that you want to increment counter once, when the value in reedCounter becomes a multiple of 6, not every time through loop(), when the value of reedCounter is a multiple of 6. Of course, fixing the code is up to you, since we can't see the rest of it.

Just make sure that your if is executed only when reedCounter actually changes.

You are apparently executing it in a busy-loop without checking whether reedCounter changed. This is why your minutes are rapidly incremented on every iteration of that busy-loop.

Sorry for not including the code, and thank you both for your quick replies.

Anyway, the whole of the code;

#include <LiquidCrystal.h>
const int reedPin = 10;
const int rs = 12, en = 11, d4 = 5, d5 = 4, d6 = 3, d7 = 2;
const int safetySwitch = 9;
const int ledRedPin = 14;
const int ledGreenPin = 15;
const int ledPin = 8;


int reedState = 0;
int lastReedState = 0;
int reedCounter = 0;
int minuteCounter = 0;

LiquidCrystal lcd(rs, en, d4, d5, d6, d7);

void setup() {

  pinMode(reedPin, INPUT);
  pinMode(safetySwitch, INPUT);
  
  pinMode(ledRedPin, OUTPUT);
  pinMode(ledGreenPin, OUTPUT);
  
  lcd.begin(16, 2);
  lcd.setCursor(0,0);
  lcd.print("Wait time:");
  lcd.setCursor(10,0);
  lcd.print(minuteCounter);
  lcd.setCursor(2,1);
  lcd.print(reedCounter);
  
}

void loop() {
reedState = digitalRead(reedPin);
 if(reedState != lastReedState) {
  if(reedState == LOW){
reedCounter++;
  lcd.setCursor(2,1);
  lcd.print(reedCounter);
digitalWrite(ledPin, HIGH);
 }else{
  digitalWrite(ledPin, LOW);
 }
 delay(50);
 }
   lastReedState = reedState;

   if(reedCounter % 6 == 0) {
   minuteCounter++; 
   lcd.setCursor(10,0);
   lcd.print(minuteCounter); 
}
}

It is incomplete, so please ignore the other inputs.

Thanks again.

Well, just place your if into the same branch after the reedCounter++; line:

 if(reedState != lastReedState) {
  if(reedState == LOW){
   reedCounter++;

   lcd.setCursor(2,1);
   lcd.print(reedCounter);

   if(reedCounter % 6 == 0) {
    minuteCounter++; 
    lcd.setCursor(10,0);
    lcd.print(minuteCounter); 
   }

   digitalWrite(ledPin, HIGH);
  }else{
   digitalWrite(ledPin, LOW);
  }
  delay(50);
 }

Montmorency Amazing thank you so much, makes much more sense!