'------------------------------------------------------ ' Early experiments trying to read RPM ' Option Explicit '------------------------------------------------------ ' Constants Const InputPin as Byte = 14 'Our input pin Const SampleRate as Single = 0.2 '1 second sample rate ' Timer Stuff Public TimeElapsed as Single Public LastSampleTime as Single ' Variables Public InputValue as Byte Public StoredValue as Byte Public RotationCounter as Integer Public RotationSpeed as Integer '------------------------------------------------------ Public Sub Main() ' Init InputValue = 0 StoredValue = 0 RotationCounter = 0 RotationSpeed =0 LastSampleTime = CSng(0) ' --- Main Program Loop ---------------- Do Call DetectRotation Call CheckTime ' Log Value StoredValue = InputValue Loop ' --- Main Program Loop ---------------- 'Call Delay(0.4) End Sub '------------------------------------------------------ Public Sub DetectRotation() ' Detect Rotations InputValue = GetPin(InputPin) if StoredValue = 0 then if InputValue = 1 then Debug.Print "Beat" RotationCounter = RotationCounter + 1 Debug.Print CStr(RotationCounter) end if end if End Sub '------------------------------------------------------ Public Sub CheckTime() TimeElapsed = Timer() 'Debug.Print "---TimeElapsed: "; 'Debug.Print CStr(CInt(TimeElapsed)) 'Debug.Print "---LastSampleTime: "; 'Debug.Print CStr(CInt(LastSampleTime)) if TimeElapsed - LastSampleTime >= SampleRate then ' Check Rotations RotationSpeed = RotationCounter 'Debug.Print "Speed: " & CStr(RotationSpeed) Debug.Print CStr(RotationSpeed) ' Reset Counter & Sample Time RotationCounter = 0 LastSampleTime = TimeElapsed end if End Sub