B4R Code Snippet measuring low frequenzy with ADXL335

B4X:
#Region Project Attributes
    #AutoFlushLogs: True
    #CheckArrayBounds: True
    #StackBufferSize: 300
#End Region

Sub Process_Globals
    'These global variables will be declared once when the application starts.
    'Public variables can be accessed from all modules.
    Public Serial1 As Serial
    Public xPin, yPin, zPin As Pin
    Public ti1 As Timer
 
    Public upDir As Boolean ' richtung aktuell
    Public lastVal As UInt
    Public lastMillis As ULong
    Public lastFreq As Float
 
End Sub

Private Sub AppStart
    Serial1.Initialize(115200)
    Log("AppStart")
 
    xPin.Initialize(xPin.A1,xPin.MODE_INPUT)
 
    ti1.Initialize("Tick_sub",1)
    ti1.Enabled = True
End Sub

Private Sub Tick_sub
Dim xVal As UInt = xPin.AnalogRead
Dim sensitivity As Int = 4
    If Abs(lastVal - xVal) > sensitivity Then
    Dim myMillis As ULong
    Dim myFreq As Float
    If xVal > lastVal And upDir = False Then ' richtungswechsel
        upDir = True
        myMillis = Millis - lastMillis
        myFreq = 1000/myMillis
        If Abs(lastFreq*100-myFreq*100) < myFreq*10 Then
            Log("F:",myFreq)
        End If
        lastFreq = myFreq
        lastMillis = Millis
    else If xVal < lastVal And upDir = True Then ' richtungswechsel
        upDir = False
    End If
    lastVal = xVal
End If

End Sub


... for training hip movement. Makes your milf happy:)
 
Last edited:
Top