go_away

Author Topic: Problem with using uint8_t  (Read 693 times)

0 Members and 1 Guest are viewing this topic.

Offline tzankoffTopic starter

  • Robot Overlord
  • ****
  • Posts: 121
  • Helpful? 0
Problem with using uint8_t
« 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...

Code: [Select]
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!
« Last Edit: June 04, 2012, 04:19:22 AM by tzankoff »

Offline Webbot

  • Expert Roboticist
  • Supreme Robot
  • *****
  • Posts: 2,132
  • Helpful? 109
Re: Problem with using uint8_t
« Reply #1 on: June 04, 2012, 06:40:06 AM »
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)
Webbot Home: http://webbot.org.uk/
WebbotLib online docs: http://webbot.org.uk/WebbotLibDocs
If your in the neighbourhood: http://www.hovinghamspa.co.uk

Offline jkerns

  • Robot Overlord
  • ****
  • Posts: 248
  • Helpful? 12
Re: Problem with using uint8_t
« Reply #2 on: June 04, 2012, 07:46:56 AM »
Check to see if the value is between 100 and 999?
I get paid to play with robots - can't beat that with a stick.

http://www.ltu.edu/engineering/mechanical/bachelor-science-robotics-engineering.asp

Offline tzankoffTopic starter

  • Robot Overlord
  • ****
  • Posts: 121
  • Helpful? 0
Re: Problem with using uint8_t
« Reply #3 on: June 04, 2012, 12:19:54 PM »
(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

Offline tzankoffTopic starter

  • Robot Overlord
  • ****
  • Posts: 121
  • Helpful? 0
Re: Problem with using uint8_t
« Reply #4 on: June 04, 2012, 11:17:04 PM »
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

 


Get Your Ad Here