Keyboard input questions

I am developing a crystallographic program and need to get user input. The input that I need includes the lengths of the crystal axes and the angles between the axes. These numbers are precise, and the parameter sliders are awkward to use for exact numbers.
I think that I would like to use the keyboard. Also, I would like to be able to fill in some values, and let the user change them. For example, once the user puts in the value for the length of the x axis, I would like to use that number to fill in the values of the y and z axes, but let the user change the values if he needs to. I would also put in a default right angle between the axes, but allow it to be changed.

I found Stacey’s vector UI, but I could not figure out how to get it into a codea project, so I don’t know if it will do what I want.

I have three questions:

  1. Is there a better input scheme than the one that I have outlined?
  2. Is the vector UI appropriate, or is there a better way to do what I want to do?
  3. How do I get the code (e.g. vector UI) into a project? I tried cut and paste, but I cannot “select” the vector UI code.

Thanks!

If you found Stacey’s page, he makes a few suggestions on apps to use to cut and paste his code at the bottom of his main page. I use IUnarchive Lite that Bortel mentioned.

As far as the rest direct numeric keyboard input sounds best.

Thanks, ldpa41001. I had not read the bottom of Stacey’s page. I was able to use GoodReader to cut and paste the code.

An example of a “storage winch” calculation sheet with keyboard input and text.
In the past I made several (a lot) of those calculations, but in Excel, including graphs.
But now it is a lessons for me how to use Codea. You can see the “difference” amount of code for inputting/presentation of variables and the needed calculation.
It is not finished, I want to make a pop-up window to save and read the variables.
Yes, it can be better.
Tap a value in the input field to change it. Use your iPad in Portrait mode.
I used MAIN, class Input and class Output.
Input and Output will follow, because the message was to long?



-- Use this function to perform your initial setup
function setup()
    displayMode(FULLSCREEN)
    
    print("Hello World!")
    watch("cycleTime")
    
    textMode(CORNER)
    fill(0, 0, 0, 255)
    font("CourierNewPS-BoldMT")
    fontSize(15)
    dR = fontSize()+4
    
    rLayer   = {}
    lWinding = {}
    
    n       = {}
    n_Perc  = {}
    M_Avail = {}
    M       = {}
    M_Perc  = {}
    P       = {}
    
    Input:init()
    
        
end

-- This function gets called once every frame
function draw()
    
    background(187, 187, 181, 255)
   
    local pi   = math.pi
    local sqrt = math.sqrt
    local rads = 2*pi/60
     
    Input:var()
    
    layers    = val1[2]
    dCable    = val1[3]
    pitch     = val1[4]
    dDrum     = val1[5]
    motors    = val1[6]
    iTot      = val1[7]
    effM      = val1[8]
    gravity   = val1[9]
    
    n_Motor   = val2[2]
    M_Motor   = val2[3]

    Vneeded   = val2[7]
    load      = val2[8]
    
    --Calculations Genaral
    P_Motor  = rads * n_Motor * M_Motor/1000
    
    Fneeded  = load * gravity

    --Calculations Layers
    for i = 1, layers do
        if i == 1 then
            rLayer[i] = dDrum/2 + dCable/2
        else
            rLayer[i] = rLayer[i-1] + sqrt(dCable^2 - (pitch/2)^2)
        end
        
        lWinding[i] = (rLayer[i] * 2 * pi)/1000
        
        n[i] = Vneeded / lWinding[i] * iTot
        n_Perc [i] = n[i] / n_Motor * 100
        
        M_Avail[i] = math.min((P_Motor*1000)/(rads*n[i]),M_Motor)
        M[i] = ( Fneeded*rLayer[i]/1000)/(iTot*motors)*1000/effM
        M_Perc[i] = M[i] / M_Motor * 100
        
        P[i] = rads * n[i] * M[i] / 1000
        

    end
    
    Output:var()
       
    cycleTime = DeltaTime*1000
    text(cycleTime,700,4)
    
end

Greetings, Dirk.nl

Class Input


Input = class()

function Input:init()

    --Left Input Field
    name1 = {}
    name1[1]  = "--Winch--"
    name1[2]  = "Layers:"
    name1[3]  = "Cable Diam:"
    name1[4]  = "Pitch of Rope:"
    name1[5]  = "Drum Diam:"
    name1[6]  = "Motors:"
    name1[7]  = "Gearbox i:"
    name1[8]  = "Mech Eff:"
    name1[9]  = "Gravity:"

    unit1 = {}
    unit1[1]  = ""
    unit1[2]  = ""
    unit1[3]  = "[mm]"
    unit1[4]  = "[mm]"
    unit1[5]  = "[mm]"
    unit1[6]  = "[x]"
    unit1[7]  = ""
    unit1[8]  = ""
    unit1[9]  = "[m/s2]"
    
    val1 = {}
    val1[1]  = 0
    val1[2]  = 34
    val1[3]  = 50.8
    val1[4]  = 52.4
    val1[5]  = 1025.5
    val1[6]  = 1
    val1[7]  = 34.2840
    val1[8]  = 0.95
    val1[9]  = 9.81

    frac1 = {}
    frac1[1]  = "%0.2f"
    frac1[2]  = "%0.0f"
    frac1[3]  = "%0.2f"
    frac1[4]  = "%0.2f"
    frac1[5]  = "%0.2f"
    frac1[6]  = "%0.0f"
    frac1[7]  = "%0.4f"
    frac1[8]  = "%0.2f"
    frac1[9]  = "%0.2f"

    --Right Input Field    
    name2 = {}
    name2[1]  = "--Motor--"
    name2[2]  = "Nom Speed:"
    name2[3]  = "Torque (Nom):"
    name2[4]  = "Power:"
    name2[5]  = ""
    name2[6]  = "--Needed--"
    name2[7]  = "V wire:"
    name2[8] = "Load:"
    name2[9] = "F wire:"

    unit2 = {}
    unit2[1]  = ""
    unit2[2]  = "[rpm]"
    unit2[3]  = "[Nm]"
    unit2[4]  = "[kW] (Calc)"
    unit2[5]  = ""
    unit2[6]  = ""
    unit2[7]  = "[m/min]"
    unit2[8] = "[Tonnes]"
    unit2[9] = "[kN] (Calc)"

    val2 = {}
    val2[1]  = 0
    val2[2]  = 1000
    val2[3]  = 4774
    val2[4]  = 0
    val2[5]  = 0
    val2[6]  = 0
    val2[7]  = 126
    val2[8] = 7
    val2[9] = 0

    frac2 = {}
    frac2[1]  = "%0.2f"
    frac2[2]  = "%0.2f"
    frac2[3]  = "%0.2f"
    frac2[4]  = "%0.2f"
    frac2[5]  = "%0.2f"
    frac2[6]  = "%0.2f"
    frac2[7]  = "%0.2f"
    frac2[8] = "%0.2f"
    frac2[9] = "%0.2f"
    
    i  = 0
    a1 = 0
    a2 = 0
    buffer = ""

end

function Input:var()
    
    local R1 = HEIGHT-10
    local C1 = 10
    local C2 = 200
    local C3 = 35
    local C4 = WIDTH/2+C1
    local C5 = 200
    local C6 = 35
    
    x = CurrentTouch.x
    y = CurrentTouch.y
    z = CurrentTouch.state    
    
    text("Input Field:",C1,R1-dR)
    
    --Left Input Field
    for i = 1, #name1 do
        row = R1 - dR*(i+2)
        text(name1[i],C1,row)
        int = math.floor(val1[i])
        if val1[i] == 0 then
            t = ""
        else
            t = string.format(frac1[i],val1[i])
        end
        text(t,C1+C2-textSize(int),row)
        text(unit1[i],C1+C2+C3,row)
        
        if  x > C1 and x < C4 and y > row and y < (row+dR) and
            val1[i] ~= 0 and a1 == 0 and a2 == 0 and z == BEGAN then
            a1 = i
        end    
    end

    --Right Input Field
    for i = 1, #name2 do
        row = R1 - dR*(i+2)
        text(name2[i],C4,row)
        int = math.floor(val2[i])
        if val2[i] == 0 then
            t = ""
        else
            t = string.format(frac2[i],val2[i])
        end
        text(t,C4+C5-textSize(int),row)
        text(unit2[i],C4+C5+C6,row)
        
        if  x > C4 and y > row and y < (row+dR) and 
            val2[i] ~= 0 and a2 == 0 and a1 == 0 and z == BEGAN then
            a2 = i
        end    
    end
    
    --Left Input Field    
    if a1 > 0  then
        showKeyboard()
        buffer = keyboardBuffer()
        text(name1[a1].. "?  "..buffer,150,R1-dR)
                
        function keyboard(key)
            if string.byte(key) == 10 then
                if #keyboardBuffer() > 0 then
                    val1[a1] = buffer
                end
                hideKeyboard()
                a1 = 0
                    
            end 
        end
    end    

    --Right Input Field
    if a2 > 0  then
        showKeyboard()
        buffer = keyboardBuffer()
        text(name2[a2].. "?  "..buffer,150,R1-dR)
                
        function keyboard(key)
            if string.byte(key) == 10 then
                if #keyboardBuffer() > 0 then
                    val2[a2] = buffer
                end
                hideKeyboard()
                a2 = 0
                    
            end 
        end
        
    end
    
    R_end = R1 - math.max(#name1,#name2)*(dR) - dR*2
    
    
end

function Input:touched(touch)
    -- Codea does not automatically call this methodm
end

Class Output


Output = class()

function Output:init(x)

end

function Output:var()
    
    local R1 = R_end - dR*2
    local R2 = R1 - dR
    local C1 = 10
    local C2 = 110
    local C3 = 210
    local C4 = 310
    local C5 = 410
    local C6 = 510
    local C7 = 610
    local C8 = 710

    --Header 1
    text("Layer"  ,C1,R1)
    text("n/motor",C2,R1)
    text("n/motor",C3,R1)
    text("M avail",C4,R1)
    text("M/motor",C5,R1)
    text("M/motor",C6,R1)
    text("P/motor",C7,R1)
    
    --header 2
    text(""       ,C1,R2)
    text(" [rpm]" ,C2,R2)
    text("  [%]"  ,C3,R2)
    text(" [Nm]"  ,C4,R2)
    text(" [Nm]"  ,C5,R2)
    text("  [%]"  ,C6,R2)
    text(" [kW]"  ,C7,R2)   

    --Layer vars    
    for i = 1, layers do
        row = R1 - dR*(i+1)
        t = string.format("%0.0f", i)
        text(t,C1+30-textSize(t),row)
        
        t = string.format("%0.2f", n[i])
        text(t,C2+65-textSize(t),row)
        
        t = string.format("%0.2f", n_Perc[i])
        text(t,C3+55-textSize(t),row)
        
        t = string.format("%0.2f", M_Avail[i])
        text(t,C4+65-textSize(t),row)
        
        t = string.format("%0.2f", M[i])
        text(t,C5+65-textSize(t),row)
        
        t = string.format("%0.2f", M_Perc[i])
        text(t,C6+55-textSize(t),row)

        t = string.format("%0.2f", P[i])
        text(t,C7+60-textSize(t),row)
    end

    --General vars    
    val2[4]  = P_Motor
    val2[9]  = Fneeded
    
end

function Output:touched(touch)
    -- Codea does not automatically call this method
end