私はVisual StudioとWindows 10のIoTを通してラズベリーのC#を試しています。すべてを動かすために私を永遠に連れて行ったが、ゆっくりとそこに着いた。私は彼らの古い2歳のチュートリアルに続いて私のledsの仕事を得た。私は今、ブレッドボードにボタンを追加してLEDをオン/オフするようにしています...悲しいことに、これはまったく動作しません。それはValueChangedが決して引き起こされないようなものです。C#のラズベリー3プッシュボタン#
私は、このガイドに従っ:thequestionが来る前に、はい、私はあまりにもGPIO5を使用してみました1本のグランドに直接ピンとGPIO18に他の1(ピン12)
:https://developer.microsoft.com/en-us/windows/iot/samples/pushbutton
私のボタンが同様に配線されています。以前はPythonスクリプトで作業していたので、GPIO18に戻りました。
これは私が実行しようとしているコードがありますが、ボタンの問題を抱えて(LEDが細かいです):私が言ったように
public sealed class StartupTask : IBackgroundTask
{
private GpioController gpio = GpioController.GetDefault();
private GpioPin pinRed;
private GpioPin pinBlue;
private GpioPin pinButton;
private GpioPinValue pinValue;
private const int BLUE_PIN = 19;
private const int RED_PIN = 26;
private const int BUTTON_PIN = 18;
public void Run(IBackgroundTaskInstance taskInstance)
{
Debug.WriteLine("initialising");
InitGpio();
if (pinRed != null)
{
pinValue = GpioPinValue.High;
pinRed.Write(pinValue);
pinBlue.Write(pinValue);
}
}
private void InitGpio()
{
gpio = GpioController.GetDefault();
if (gpio == null)
{
pinRed = null;
pinBlue = null;
pinButton = null;
Debug.WriteLine("Failed starting GPIO");
return;
}
pinValue = GpioPinValue.Low;
pinRed = gpio.OpenPin(RED_PIN);
pinRed.Write(pinValue);
pinRed.SetDriveMode(GpioPinDriveMode.Output);
pinBlue = gpio.OpenPin(BLUE_PIN);
pinBlue.Write(pinValue);
pinBlue.SetDriveMode(GpioPinDriveMode.Output);
pinButton = gpio.OpenPin(BUTTON_PIN);
if (pinButton.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
{
Debug.WriteLine("Is supported");
pinButton.SetDriveMode(GpioPinDriveMode.InputPullUp);
}
else
{
Debug.WriteLine("Not supported");
pinButton.SetDriveMode(GpioPinDriveMode.Input);
}
pinButton.DebounceTimeout = TimeSpan.FromMilliseconds(50);
pinButton.ValueChanged += buttonValueChange;
Debug.WriteLine("GPIO initialised");
}
private void buttonValueChange(GpioPin sender, GpioPinValueChangedEventArgs e)
{
Debug.WriteLine("here");
if (e.Edge == GpioPinEdge.FallingEdge)
{
Debug.WriteLine("Button push");
pinValue = (pinValue == GpioPinValue.Low) ? GpioPinValue.High : GpioPinValue.Low;
pinRed.Write(pinValue);
pinBlue.Write(pinValue);
}
else
{
Debug.WriteLine("Button release");
}
}
}
はい、デバッグラインの多くは、ラズベリーのC#を試す(InputPullUpサポートされています)。 buttonValueChangeの "here"は決してトリガされません。私はPython上でまったく同じ配線設定を行い、同じピンで完璧に動作しました。
'pinButton.DebounceTimeout = TimeSpan.FromMilliseconds(50);の直前に' var dm = pinButton.GetDriveMode(); 'のようなものを追加して、実際にどのドライブモードが設定されているか確認できますか? –
ちょうどチェックされて、それが返されます:InputPullUp – Psychokiller1888