I am trying to implement a user interface by way of a 2X16 LCD display and an analog 5 button input.
The extract of code below obtains the SSIDs of available networks and displays the initial one from the wfi.scan array on the second line of the LCD display. The intent of the remainder of the code is to loop while scanning the button input via pin A0. Selecting the DOWN button should replace the SSID display with the next in the array and selecting the UP arrow should move the selection back through the array. The loop should continue until the SELECT button is pressed, at which point the SSID will be saved and the sub exited.
However after displaying Select network then the initial SSID on the second row of the LCD display, the code crashes with an Exception (28): error message.
It seems that after executing the loop perhaps a dozen times the crash occurs. I suspect a memory issue, but I don't know how to diagnose that.
Should my code achieve the desired user interface or is there a coding flaw?
The extract of code below obtains the SSIDs of available networks and displays the initial one from the wfi.scan array on the second line of the LCD display. The intent of the remainder of the code is to loop while scanning the button input via pin A0. Selecting the DOWN button should replace the SSID display with the next in the array and selecting the UP arrow should move the selection back through the array. The loop should continue until the SELECT button is pressed, at which point the SSID will be saved and the sub exited.
B4X:
Sub Process_Globals
Public Serial1 As Serial
Private usocket As WiFiUDP
Private wifi As ESP8266WiFi
Private ip(4) As Byte
Private port As UInt = 3661
Private astream As AsyncStreams
Private bc As ByteConverter
Private lcd As LiquidCrystal
Private TextLine(5) As String = Array As String (" ABCDEFGHIJKLMNO", "PQRSTUVWXYZ01234", "56789abcdefghijk", "lmnopqrstuvwxyz?", "!@#$%^&*()+-=_/ ")
Private LineNo As UInt = 0
Private PIN_A0 As Pin
Private btnValues() As UInt = Array As UInt(50, 250, 450, 650, 850, 1025) ' RIGHT, UP, DOWN, LEFT, SELECT, NO BUTTON
Private btn As UInt
End Sub
Sub ScanNetworks
lcd.Write("Scan for network")
Dim numberOfNetworks As Byte = wifi.Scan
Dim reading As UInt = PIN_A0.AnalogRead
For j = 0 To btnValues.Length - 1
If reading < btnValues(j) Then
btn = j
Log("Read button initially: ",btn)
Exit
End If
Next
Dim i As UInt = 0
Do Until btn = 4 'SELECT
lcd.Clear
lcd.Write("Select network")
lcd.SetCursor(0, 1)
lcd.Write(wifi.ScannedSSID(i))
reading = PIN_A0.AnalogRead
For j = 0 To btnValues.Length - 1
If reading < btnValues(j) Then
btn = j
Exit
End If
Next
If btn = 1 And i > 0 Then 'UP
i = i - 1
End If
If btn = 2 And i < numberOfNetworks - 2 Then 'DOWN
i = i + 1
End If
Loop
GlobalStore.Put(0, wifi.ScannedSSID(i))
End Sub
However after displaying Select network then the initial SSID on the second row of the LCD display, the code crashes with an Exception (28): error message.
It seems that after executing the loop perhaps a dozen times the crash occurs. I suspect a memory issue, but I don't know how to diagnose that.
Should my code achieve the desired user interface or is there a coding flaw?