Je suis développer un compteur d'impulsions (pièce compteur) dans pi de framboise avec des fenêtres 10 noyau IOT, et je dois compter les impulsions qui ont un intervalle de temps de 25 millisecondes comme celui-ci:Comment puis-je compter les entrées d'impulsions avec un certain intervalle de temps?
0,05 € - 1 impulsion 0,10 € - 2 impulsions 0,20 € - 4 impulsions 0,50 € - 10 impulsions 1 € - 20 impulsions 2 € - 40 impulsions
comme cette image: pulses
I besoin d'imprimer le nombre d'impulsions (pour avoir la valeur insérée) lorsque l'intervalle de temps est dif erent de 25 millisecondes.
Je possède ce code:
public MainPage()
{
this.InitializeComponent();
InitGPIO();
}
private void InitGPIO()
{
var gpio = GpioController.GetDefault();
if (gpio == null)
{
GpioStatus.Text = "There is no GPIO controller on this device.";
}
coinPin = gpio.OpenPin(coin_Pin);
if (coinPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
{
coinPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
} else
{
coinPin.SetDriveMode(GpioPinDriveMode.Input);
}
coinPin.DebounceTimeout = TimeSpan.FromMilliseconds(25);
coinPin.ValueChanged += coinPin_ValueChanged;
GpioStatus.Text = "GPIO pins initialized correctly.";
}
private void coinPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e)
{
if (e.Edge == GpioPinEdge.FallingEdge)
{
counter++;
}
var task = Dispatcher.RunAsync(CoreDispatcherPriority.Normal,() =>
{
if (e.Edge == GpioPinEdge.FallingEdge)
{
//counter++;
var time = PulseIn(coinPin, e.Edge);
value = (counter * 5);
value100 = value/100;
//money.Text = "Eur: " + (decimal)value100 + " €";
if (time != 25)
{
money.Text = "Eur: " + (decimal)value100 + " €";
GpioStatus.Text = "" + time;
} else
{
GpioStatus.IsEnabled = false;
}
//GpioStatus.Text = "" + time + "";
} else
{
///GpioStatus.Text = "" + coinPin.DebounceTimeout;
}
});
}
private double PulseIn(GpioPin pin, GpioPinEdge edge)
{
var sw = new Stopwatch();
while (edge.Equals(GpioPinEdge.RisingEdge))
{
//sw.Start();
}
sw.Start();
if (!edge.Equals(GpioPinEdge.RisingEdge))
{
//sw.Stop();
}
sw.Stop();
return sw.Elapsed.TotalMilliseconds;
}
private const int coin_Pin = 24;
private int counter = 0;
private double value = 0;
private double value100 = 0;
private GpioPin coinPin;
Pouvez-vous me aider s'il vous plaît? Merci beaucoup.
J'ai mis à jour la question avec un exemple de saisie de 2 pièces (0,2 € et 0,05 €) le résultat devrait être de 0,20 € et 0,25 €, et affichera maintenant "0,05 0,1 0,15 0,20 0,25 "... Je n'ai besoin que de montrer la valeur totale. – rmntavares
Comment entrez-vous de 0,2 €? N'a-t-il pas quatre impulsions? –