Sub Process_Globals
Public Serial1 As Serial
End Sub
Private Sub AppStart
Serial1.Initialize(115200)
Log("AppStart")
Dim p As Pin
p.Initialize(0, p.MODE_INPUT)
RndSeed(p.AnalogRead)
Dim values(10) As Double
Log("before:")
For i = 0 To values.Length - 1
values(i) = Rnd(0, 100000) / 1000
Log(values(i))
Next
SortArray(values)
Log("after:")
For i = 0 To values.Length - 1
Log(values(i))
Next
End Sub
'Bubble sort
Sub SortArray(Values() As Double)
Dim temp As Double
Dim sorted As Boolean = False
Do While sorted = False
sorted = True
For i = 0 To Values.Length - 2
If Values(i) > Values(i + 1) Then
temp = Values(i)
Values(i) = Values(i + 1)
Values(i + 1) = temp
sorted = False
End If
Next
Loop
End Sub