Se ho ben capito la tua domanda, la risposta dovrebbe essere:
B4X:Dim y As Float
dim Y as Float
y = 4.5f;
dim Y as Float
y = 4
dim pippo as string
pippo="ciao"
dim pippo as string
pippo=1
dim pippo as int
pippo=10
Dim m_FilteringFactor As Float
m_FilteringFactor= 4.5f;
Dim m_Value As Float
Float m_Value = 0.0f
Dim m_Value As Double
Dim i_Value As Double
i_Value=Values(0)
m_Value = m_Value * (1.0f - m_FilteringFactor) + i_Value * m_FilteringFactor;
A volte si cerca quello che con la semplicità si ottiene.....Una volta dichiarata la variabile come float, l'assegnazione:
var = 0.5
Tutto qua
(tutte quelle f non servono, non so nemmeno se siano accettate dal compilatore)
m_Value = m_Value * (1.0f - m_FilteringFactor) + i_Value * m_FilteringFactor;
m_Value = m_Value * (1 - m_FilteringFactor) + i_Value * m_FilteringFactor
Dim m_FilteringFactor, m_Value As Double
m_FilteringFactor = 4.5
m_Value = 0
m_Value = m_Value * (1 - m_FilteringFactor) + Values(0) * m_FilteringFactor
Excellent as always, we would be honored to see you more often in the Italian forumWhat exactly doesn't work ?
The equation is a low pass filter for a series of values. Look at the bottom of this wikipedia page, in english, the italian page doesn't show the equations.
How do you use it ?
Instead of the code in post #6 try this code:
B4X:Dim m_FilteringFactor, m_Value As Double m_FilteringFactor = 4.5 m_Value = 0 m_Value = m_Value * (1 - m_FilteringFactor) + Values(0) * m_FilteringFactor
Don't use Float use Double, internally B4A calculates with Doubles..
You can use the NumberFormat function for the display.
You may also 'play' with the FilteringFactor.
Sorry, I don't speak italian.
Sub Sensor_SensorChanged (Values() As Float)
MylblDeg.text=MovingAVG(values(0))
end sub
Sub MovingAVG(MagneticRow As Float)
' ******************FILTER SENSOR *********************************************************
CurValue=Round2(MagneticRow,1)
If CurValue = OldValue OR CurValue + 0.1 = OldValue OR CurValue - 0.1 = OldValue Then
Return Glob_SensorFilter
Else
Glob_SensorFilter = (Glob_SensorFilter * Glob_MayFilter) + (MagneticRow * (1.0 - Glob_MayFilter))
OldValue=CurValue
Return Glob_SensorFilter
End If
End Sub