Asked — Edited

Numeric Keypad - Mobile Builder

Good Afternoon,

I am looking to create a numeric keypad within ARC. 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


ARC Pro

Upgrade to ARC Pro

ARC Pro is your gateway to a community of like-minded robot enthusiasts and professionals, all united by a passion for advanced robot programming.

United Kingdom
#1  

One method would be to use simple math.

First digit is hundreds Second is tens Third is units

So, take the script, when the first number is used multiply it by 100 and add it to the register. Second, multiply by 10 and add to the register and finally add the third to the register.

Something like (this is just the math part, receiving the number data is a different matter):


$keycode = ($keypad1*100) + ($keypad2 * 10) + $keypad3

#2  

Thank You Rich,

To go one step further, my keypad would be 0-9. My thought was to make it easy by using just one string value and combining that, but looking at your script above, that wont work.

So, how would you get the data into the string values?

United Kingdom
#3  

I presumed it would be 0 to 9. You end up with a 3 digit code which varies between 000 and 999, it's a numeric value at the end of the day which can be used. Failing that, use quotes to associate the number with a string rather than a value. "1" + "2" + "3" = "123" whereas 1 + 2 + 3 = 6.

Getting the data to the string will totally depend on the keypad and how it works, how it's connected, how ARC is aware of the activity on the keypad etc.

#4  

What is the best way to configure the buttons?

United Kingdom
#5  

I need more information on the keypad to be able to even think about how to answer that. How does it work? How does it connect to the EZ-B or the PC? Is it just 10 push switches or does it have it's own PIC? etc. etc. etc.

Trinidad/Tobago
#6  

where would the entered number go? is it for calculations?

#7  

No, I would use the button from the Mobile Interface. When you press the button, my first thought was to create a string value. Imagine a your tablet with buttons in a layout of a simply keypad. The button press would make $Button1 = "1" . In my main script I would declare that $Button1 = "". Then somehow recognize that change into an if then statement. Then use that if then statement to ControlCommand the numbered script. No hardware keypad all use from software.

Hope that clears things up.

United Kingdom
#8  

Sorry I misunderstood, I thought you had an actual keypad.

In that case it's easy. It's a lot of scripts which are pretty much the same but it's easy.

For instance, button 4 script would be;


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

Button 0 would be;


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

However the $keycode = $keycode + 0 lines are redundant.

Your keycode script would also need to be running;


: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)

Each button script will check the position in the code and add the correct number to the position. The other script will loop, wait for the sequence to be finished and then check the number, run the required code, reset the sequence to 1 and wait for a completed code again.