Welcome to Synthiam!

Program robots using technologies created from industry experts. ARC is our free-to-use robot programming software that makes features like vision recognition, navigation and artificial intelligence easy.

Get Started
Asked — Edited

Numeric Keypad - Mobile Builder

Good Afternoon,

I am looking to create a numeric keypad within EZ-Builder. I want to pre-program a script for example 133. How do you combine the numbers into a string value, and that value is a number?

Thanks
WayneA

AI Support Bot
Related Content
Synthiam
Based on your post activity, we found some content that may be interesting to you. Explore these other tutorials and community conversations.
#10  
@VGosine Yes, a future project would be to expand on this keypad to do calculations. Do you have any ideas on how it could be done?
#11  
@rich I tried to use your code, it is way over my head. Thank You for the help, I got to break down your code and try to understand it a bit better.
Trinidad/Tobago
#12  
@WayneA if you wanted to do calculations with the number stored you would need to setup variables that would store a number entered, it would then store another variable for the operation when the operation is entered it would reset the buttons for entering a new number.

When i have some time i will see if i could come up with a similar interface and share the project with you.
United Kingdom
#13  
@WayneA, I don't know how I can break the code down further for you. Which part(s) are you struggling to get your head around?
#14  
I guess I do not understand the sequences that you have set up. I guess my thinking process is that for each button that is pressed, the script within the button is checking the running script to see if any other button is pressed. If it is, the button script knows how to handle.

Another thought that I had was to to just setup a string value, lets say $N. Create my 10 buttons and each press of the button would make the string value of $N = "1". Every time the $N value changed store that into another string separated by commas. Depending the amount of commas and the amount of numbers contained in the string, the output would equal to for example "444".

Then, another thought I had was to shift the string value down. (I am taking an online course to help me get the basics of code - Covering Left Shift Bits and Right Shift Bits.)

Then another thought was to re write my project to just press a button and CC("444", scriptstart )
United Kingdom
#15  
Make 10 script buttons in the mobile interface, label them 0 to 9

For each button have a script like this one (this example is for number 4)

Code:


IF($sequence = 1)
$keycode = 4000
$sequence = 2
Halt()
ElseIf($sequence = 2)
$keycode = $keycode + 400
$sequence = 3
Halt()
ElseIf($sequence = 3)
$keycode = $keycode + 40
$sequence = 4
Halt()
ElseIf($sequence = 4)
$keycode = $keycode + 4
$sequence = 0
Halt()
Else
SayEZB("There has been an error")
EndIf


To change for other numbers simply replace the 4000, 400, 40 and 4 for whichever number you are writing the script for. I.E. For number 2 use 2000, 200, 20 and 2. For 1 use 1000, 100, 10 and 1.

After each button press the sequence is increased so the scripts will know what value to add to the keycode.

You also need the script running that will trigger the requested scripts or actions when the code is sent to it. That's the other script I posted. You could have up to 10,000 different scripts or actions triggered which would require 10,000 IF statements. Obviously I haven't included all 10,000!

This is the script.

Code:


:loop
WaitFor($sequence = 0)
IF($keycode = 0)
# Run action for 0000
ElseIf($keycode = 1)
# Run action for 0001
...
ElseIf($keycode = 4444)
# Run action for 4444
ElseIf($keycode = 4445)
# Run action for 4445
...
ElseIf($keycode = 9998)
# Run action for 9998
ElseIf($keycode = 9999)
# Run action for 9999
Else
SayEZB("There has been an error")
EndIf
Sleep(200)
$sequence = 1
Goto(loop)


When the sequence in the number scripts is complete it resets the $sequence variable to 0. The above code waits for that to become 0 and then checks the sequence and runs the code between that sequences ELSEIF and the next ELSEIF. If the code doesn't match it runs the ELSE code so you needn't do all 10,000 statements.

At the end of the above code it resets the sequence to 1 again so the keypad code number scripts know the digit position. It then loops back to the start and waits for the sequence to be set as 0 again before it moves past the WaitFor line.

Most of the work is done for you above you just need to change the script for each number for the keypad code and fill in the ControlCommands in the second script above.
#16  
Thank You Rich, one more question, when the script runs, the order of numbers is wrong, for instance, if I click 732, the string value is 237, anyway to make outcome in the right order?
United Kingdom
#17  
Enter it in the right order. You could easily add in a cancel button which would simply reset the $keycode to 0 and $sequence to 1 but you couldn't expect a human to know you meant 237 if you said 732 so how can you expect a computer?

The cancel button code would be

Code:


$sequence = 1
$keycode = 0
Trinidad/Tobago
#19  
@WayneA Have a look at this. It's still a work in progress but it should give you an example on how to do calculations and receive the entered number in the correct order if you haven't fixed that problem yet


Calculator - Mobile Interface

The only thing wrong with it is that there is no decimal point and that you have to hit equal after each operation excluding the initial number input.
#20  
I have not been able to figure out the order yet. VGosine your script was a really big help. I truly do thank you.
#21  
After almost a couple of hours playing with both scripts, I have decided to just give up. Thank You for all of your help.
Trinidad/Tobago
#22  
I just made some changes to the file try it again ... And my script enters the number in the order you enter it so if you type 6 then 8 then 2 you will have 682 in a variable stored...
#23  
Try your calculator file that you posted?
Trinidad/Tobago
#24  
Yeah if you try the calculator file, when you press the numberpad buttons they enter the number in the order you press it... i'm not sure it that's helpful but this was the code:

Code:


IF ($order=0)
$number=$currentnum
$order++
ELSE
$number=$number*Power(10,1)
$number=$number+$currentnum
$order++
ENDIF


This code is called when a button is pressed and the value of currentnum is changed to the number on the button you press. To run the calculator you would need to declare the variables first by starting the script "Variables".
#25  
What does the following below mean?

Code:



ELSE
$number=$number*Power(10,1)
$number=$number+$currentnum
$order++
EndIf




What if you wanted to shift or move down the input data to another string variable? Would that depend on the $order string variable right?

Code:



IF ($order=0)
$number=$currentnum
$order++



$order++ means you are adding the number one to it right
Trinidad/Tobago
#26  
The first section of code can be replaced to

Code:


ELSE
$number=$number*10
$number=$number+$currentnum
$order++
EndIf

you don't need the power function... but what this does is when you press a key it will move the first number entered to a new column and then add the new number pressed.

so if you press 1 the entered number is 1
if you press 2 the entered number is now 10+2=12
if you press 3 the entered number is now 120+3=123

that way it is just like a calculator when entering numbers on the keypad.

the entered number is stored in $number you can store this value in a different variable if you wish but it would be an integer to start not a string.
and order++ increases the amount of digits stored in $number... so by resetting order to 0 you enter a new number into the $number variable.
#27  
How would you store $number into another variable after you are done entering it?

a script to look at the count?
United Kingdom
#28  

Code:

$newvariable = $oldvariable


So...

Code:

$anothervariable = $number
Trinidad/Tobago
#29  
You would create an enter button that signifies that you are done entering a number and then you would do as Rich said to store the value in another variable.