Question - Serial.parseInt

Hi,

The Serial.parseInt function is amazing however I believe it has a major glitch when return the zero when a non integer char is introduced.

Why? Well... I am reading from the serial a digit number between 0 and 23. So far so good.

I made a constraint so when the number is above 23 or below 0 it should not be accepted.

The problem is that if I introduce another char: like a char: a, b ,c... it returns "zero" and my program accepts that non valid char as "0".

What can I do to solve this issue? For example returning -1 is OK for me but I have to change the library and if I share this software with other they also have to change that return value.

Any suggestion?

Thanks

Well... I am reading from the serial a digit between 0 and 23

There are no decimal digits greater than 9.

take a peek before you parse...

AWOL:

Well... I am reading from the serial a digit between 0 and 23

There are no decimal digits greater than 9.

I meant "number". Sorry.

BulldogLowell:
take a peek before you parse...

I'll give it a try. Thank you.

BulldogLowell:
take a peek before you parse...

Works like a charm :slight_smile: Thanks