Society of Robots - Robot Forum
Software => Software => Topic started by: tzankoff on June 04, 2012, 04:14:41 AM
-
Hi. Me again. Sorry about that.
;D
I am having a little problem using uint8_t in my code and am not sure how to go about it since I am not as familiar with C++ as a lot of the rest of you.
I am using webbotlib in AVR Studio and am using uint8_t to store numbers inputted through a keypad. The keypad is wired correctly and all the right numbers show up and are stored correctly when buttons are pressed.
What I having problems with is determining the length of the stored number. When the number is 3 characters long (i.e.:123), I want the code to do something, thus...
uint8_t keypadNum;
if (keypadNum is 3 characters long){
do something
}
Can somebody please give me a hand on how to accomplish this? Google is not being my friend on this one, though not for lack of effort.
Thank you!
-
You could use some kind of routine (like rprintf) to print the number as a string and see how long it is - but that WONT work if the user starts their number with a zero. ie What happens if their number is '000'.
So you are much better off keeping track of the number of entered digits in your software that monitors each key press: ie +1 for each key press, set to 0 if the hit the clear button, -1 if they hit backspace.
( So its not an 'uint8_t problem' - its more of a 'How do I track the number of digits entered via a kbd' kinda problem :D)
-
Check to see if the value is between 100 and 999?
-
(So its not an 'uint8_t problem' - its more of a 'How do I track the number of digits entered via a kbd' kinda problem :D)
Keypad, not keyboard...same thing, though.
Check to see if the value is between 100 and 999?
I don't have a clue why that did not even occur to me. I'm so used to doing stuff like 'variable.length' for what I am trying to accomplish that I did not even consider something for which I would normally use to check for value within a range.
The 'Hit Head Here' sign on my desk is getting worn out. :P
-
I went ahead and added the "keypadNum>=100" condition to the code not having any clue as to why I did not think of this before...other than the fact that I am an idiot. :P