Change variable using serial input?

Can somebody please point me in the right direction as to how I can increment a certain variable each time I input a specified character into the serial monitor?

The problem I have with this code below is that my arduino just seems to stop and do nothing until I enter a character in, which is a problem since I want to keep the code running in order to tune it precisely.

int incomingByte = 0;
int p = 0;

void setup() {
        Serial.begin(9600);
}

void loop() {
        if (Serial.available() > 0) {
            incomingByte = Serial.read();
             if (incomingByte == 'p') {
             p++;
             }
        }
//Rest of code here that does some boring stuff and is known to 100% work every time.
}

The problem I have with this code below is that

The problem I have is that you have offered no proof that you have a problem, and you haven't provided the real code so we can reproduce the issue.

Have a look at the examples in serial input basics. They illustrate simple reliable ways to receive data without interfering with other Arduino tasks. I imagine one of the three examples will meet your needs.

I reckon it is better to receive all the data before trying to figure out what to do with it.

...R

webdev77:
Can somebody please point me in the right direction as to how I can increment a certain variable each time I input a specified character into the serial monitor?

The problem I have with this code below is that my arduino just seems to stop and do nothing until I enter a character in, which is a problem since I want to keep the code running in order to tune it precisely.

int incomingByte = 0;

void setup() {
        Serial.begin(9600);
}

void loop() {
        if (Serial.available() > 0) {
            incomingByte = Serial.read();
            if (incomingByte == 'p') {
            p++;
            }
        }
//Rest of code here that does some boring stuff and is known to 100% work every time.
}

Where and what is p you imcrement it but its not declared

Robin2:
Have a look at the examples in serial input basics. They illustrate simple reliable ways to receive data without interfering with other Arduino tasks. I imagine one of the three examples will meet your needs.

I reckon it is better to receive all the data before trying to figure out what to do with it.

...R

Thank you. This is what I was looking for.

To those who asked, the p variable is just an integer.