I am using a 4x4 Keypad to enter data on an Arduino Uno. The letters A to D represent commands and the numbers will be values. For example: Pressing "A" followed by up to six further numbers and then "#" should give me a string "123456" which I then need to convert to an integer and store.
Something is not correct as you can see from the log output but I cannot see my mistake. In this case the value 36 should be stored in "SpeedDown" but the log shows "##" ?????
Something is not correct as you can see from the log output but I cannot see my mistake. In this case the value 36 should be stored in "SpeedDown" but the log shows "##" ?????
B4X:
A
Speed down active ....
3
6
#
Speed down finished ...
Value: ##
B4X:
#Region Project Attributes
#AutoFlushLogs: True
#CheckArrayBounds: True
#StackBufferSize: 300
#End Region
' planned screen
'
' (A) Speed Down: 20 mm/s
' (B) Hold Time: 10 mins
' (C) Speed Up: 40 mm/s
' (D) Run (*) Reset
Sub Process_Globals
Public Serial1 As Serial
Private pad As Keypad
Private KeyBuffer(6) As String
Dim vKey As Int=0
Private SpeedDown As Double=0
Private Holdtime As Long=0
Private Speedup As Double=0
Private timer1 As Timer
Private CommandActive As Int=0
Dim bc As ByteConverter
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
pad.Initialize("123A456B789C*0#D", Array As Byte(9, 8, 7, 6), Array As Byte(5, 4, 3, 2), _
"pad_KeyPressed")
timer1.Initialize("timer1_Tick",1000)
End Sub
Sub timer1_Tick
End Sub
Sub Pad_KeyPressed (Key As String)
Log(Key)
If Key = "*" Then
SpeedDown=0
Holdtime=0
Speedup=0
'ResetDisplay
Else if Key = "A" Then
'Speed down
If CommandActive>0 Then Return ' a different command key is active
CommandActive=1
Log("Speed down active ....")
vKey=0
Else if Key = "B" Then
'Hold time
If CommandActive>0 Then Return
CommandActive=2
Log("Hold time active ....")
vKey=0
Else if Key = "C" Then
'Speed up
If CommandActive>0 Then Return
CommandActive=3
Log("Speed up active ....")
vKey=0
Else if Key = "D" Then
'Run
Log("Speed down: ", SpeedDown)
Log("Hold time: ", Holdtime)
Log("Speed up: ", Speedup)
else if Key = "#" Then
'Enter pressed
Select Case CommandActive
Case 1
Log("Speed down finished ...")
SpeedDown=TransferBuffer
CommandActive=0
Case 2
Holdtime=TransferBuffer
Log("Hold time not finished ...")
CommandActive=0
Case 3
Speedup=TransferBuffer
Log("Speed up not finished ...")
CommandActive=0
End Select
else if vKey<6 Then
'put the key in the buffer.
KeyBuffer(vKey)=Key
vKey=vKey+1
End If
End Sub
Sub TransferBuffer As Int
Dim vv As String=JoinStrings(KeyBuffer)
Dim v As Int=vv
Log("Value: ",vv)
Return v
End Sub