Go Down

Topic: Arduino keyboard help (Read 73 times) previous topic - next topic

RED9000

So I need to hook up a small keyboard

and when I input numbers I want them to be read as numbers, not their ascii values.
I know the trick of - '0' but this only works for 0-9, I need to feed it larger integers like 17.
When doing it with a standard laptop
http://forum.arduino.cc/index.php?topic=220089.0
this program did me fine. Any suggestions would be much appreciated.

PaulS

Quote
I know the trick of - '0' but this only works for 0-9, I need to feed it larger integers like 17.
How are you planning to recognize that the last digit of the number has been entered?

RED9000

sorry are you referring to me using my computer to send the data or just the keyboard?

Nick Gammon

Say you want to enter the number 76521.

What buttons will you press? How does it know the difference between one number 76521 and two numbers: 765 and 21?
Please post technical questions on the forum, not by personal message. Thanks!

More info:
http://www.gammon.com.au/electronics

RED9000

#4
Nov 01, 2014, 10:36 pm Last Edit: Nov 01, 2014, 10:46 pm by RED9000
Oh sorry I see what you mean, so I have coded it so that It takes each number alone, so if I wanted 11 for example I would hit 5, A, 6, A, D, A.
so A just sends the digit to the arduino, when I send D it tells the arduino to add all the input. not the best way of doing it by any means but it works. The issue i'm running into is when I do 5, A, 6, A, D, it adds the ascii values of 5 and 6, not their integer values.
Then I have an if statement for the outcome:
for example;
if (outcome = 11){
digitalWrite(motor, HIGH);
but when it adds ascii values the outcome isn't even close, I could always just code for adding ascii values if this cant work

filk

perhaps consider using the # or * key to terminate an entry.

read the values into an array of bytes as they are input until the key you use to terminate is pressed # for example and terminate the char array with a null.

then evaluate the number entered, using the length of the array to tell you what to multiply each digit by,
last digit  by 1 2nd from last x 10 third from last x 100 etc...  so if 5 digits added you will have some 10,000s 
in your array at index 0 1000s at index 1, hundreds at index 2 tens at index 3 and units at index 5.

allowing you to hit 1, 1, #  to enter 11 ;)




RED9000

better than my solution  :D  ill try it out, thanks

filk

edit to above..  units at index 4.. 

Go Up