B4J Code Snippet [IoT] Raspberry 2/piFace: Get status of switches

This code is from one of Erels examples. I stripped it to have a straight example how to get the status of the build in switches. You need the piFace extension:
PiFace+Digital+2+for+Raspberry+Pi+5511ec19dca72.png


B4X:
'Non-UI application (console / server application)
#Region  Project Attributes
    #CommandLineArgs:
    #MergeLibraries: True
#End Region

Sub Process_Globals
    Public pface As PiFace
End Sub

Sub AppStart (Args() As String)
    pface.Initialize(0x40, 0)
    For i = 0 To 3
        Dim sw As Switch = pface.GetSwitch(i)
        sw.AddListener("switch" & i)
    Next
   
    StartMessageLoop
End Sub

Sub Switch0_StateChange(State As Boolean)
    Log("Switch 0: " & State)
End Sub
Sub Switch1_StateChange(State As Boolean)
    Log("Switch 1: " & State)
End Sub
Sub Switch2_StateChange(State As Boolean)
    Log("Switch 2: " & State)
End Sub
Sub Switch3_StateChange(State As Boolean)
    Log("Switch 3: " & State)
End Sub
 
Top