C++ Logic Verification (100 line program)

Looking for some verification of my programming logic vs. desired outcome. I will put the code first and then my desired outcome below. Thank you very very very much for taking the time to help me out on this project. :)

``````void loop() {
int dummy = 1;
IR_DIST = 22;

if (printToLCD) {

lcd.clear();
lcd.setCursor(0, 0);

char aa=actual_buf[1], bb=actual_buf[2], cc=actual_buf[3], dd=actual_buf[4];

if (aa == '6' && bb == '0' && cc == '1' && dd == '5') {
strcpy (name, "Hi Bob!");
dummy = 0;
}

if (aa == '6' && bb == '0' && cc == '1' && dd == '4') {
strcpy (name, "Hi Andrew!");
dummy = 0;
}

if (aa == '1' && bb == '0' && cc == '1' && dd == '5') {
strcpy (name, "Hi Jene");
dummy = 0;
}

if (aa == '8' && bb == '0' && cc == '2' && dd == '3') {
strcpy (name, "Hi J!");
dummy = 0;
}

printToLCD = false;

if (dummy == 0) {

lcd.clear();
lcd.setCursor(0, 0);
Serial.println(name);
lcd.print(name);
lcd.setCursor(0, 1);
Serial.println("Begin!");
lcd.print("Begin!");
delay(200);

while(lastButtonState = LOW){

float distance = 65*pow(volts, -1.10);

if (IR_DIST - distance > 1) {
counter = counter + 1;
}

if (counter != 0) {
lcd.clear();
lcd.setCursor(0, 1);
Serial.printIn(counter);
lcd.print(counter);
Serial.printIn(" items");
lcd.print(" items");
}

delay(100);

lastDebounceTime = millis();
}

if ((millis() - lastDebounceTime) > debounceDelay) {
}

}

lcd.clear();
lcd.setCursor(0, 0);
Serial.printIn("Thank you!");
lcd.print("Thank you!");
lcd.setCursor(0, 1);
Serial.printIn(counter);
lcd.print(counter);
Serial.printIn(" items");
lcd.print(" items");
delay(5000);
lcd.clear();
lcd.setCursor(0, 0);
}
}
}
``````

Desired outcome: Once in the printToLCD loop: 1- Check aa, bb, cc, dd. 2- If they match, run the dummy loop. Otherwise, don't, and break printToLCD loop back to void loop(). 3- If they match, they will enter the dummy loop. Print their name to the LCD and Serially. 4- Continue the while loop until the SPDT button is pressed. 5- Read IR Sensor distance, if greater than 1, increase a counter. 6- Make sure counter has counted at least 1 item. If so, update LCD for each counter increase. 7- Check if button has been pressed. 8- Once button pressed, exit while loop and output final counter value.

Did you intend this line...

``````             while(lastButtonState = LOW){
``````

...to be this...

``````             while(lastButtonState == LOW){
``````

Yes, excellent catch. Thank you!

It looks to me like the "while(lastButtonState == LOW){" part of your code acts like a trap. Once lastButtonState is HIGH, the while loop will never be entered again.

Finished debugging and it works like a charm. :)