Hi,
I am trying to build a wind speed sensor. For this I Count te amount of interrupts on a gpio pin that is configured as input in a certain time period.
At the end of this period I like to show the count value in a textbox on the UI.
…
private void InitAnemoTimer()
{
Anemotimer = new System.Threading.Timer(_ => OnAnemoTimerCallBack(),null, 0, Timer_Constante);
}
private void Windpin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
{
if (args.Edge == GpioPinEdge.FallingEdge)
{
windcounter=windcounter+1; //Every windpuls increment the counter.
}
}
private void OnAnemoTimerCallBack()
{
wind = windcounter; //Calculates wind
//windBox.Text = wind.ToString(); //show in texbox: this is not working
windcounter = 0; //Reset windcounter
Anemotimer.Change(0, Timer_Constante); //restarts the timer
}
On problem is that the UI is on a different tread than the system treading timer.
How can I synchronize these treads?