You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Jan 30, 2019. It is now read-only.
Hello,
when I use BackgroundApp (IoT) template I get no values from the pins.
I try it exactly as in Foreground App, but there is no event triggered when pressing the button.
Can someone tell me what I do wrong?
Here is my Code
`namespace BackgroundApplication2
{
public sealed class StartupTask : IBackgroundTask
{
private const int LED_PIN = 6;
private const int BUTTON_PIN = 5;
private GpioPin ledPin;
private GpioPin buttonPin;
private GpioPinValue ledPinValue = GpioPinValue.High;
public void Run(IBackgroundTaskInstance taskInstance)
{
InitGPIO();
}
private void InitGPIO()
{
var gpio = GpioController.GetDefault();
// Show an error if there is no GPIO controller
if (gpio == null)
{
Debug.WriteLine( "There is no GPIO controller on this device.");
return;
}
buttonPin = gpio.OpenPin(BUTTON_PIN);
ledPin = gpio.OpenPin(LED_PIN);
// Initialize LED to the OFF state by first writing a HIGH value
// We write HIGH because the LED is wired in a active LOW configuration
ledPin.Write(GpioPinValue.High);
ledPin.SetDriveMode(GpioPinDriveMode.Output);
// Check if input pull-up resistors are supported
if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
else
buttonPin.SetDriveMode(GpioPinDriveMode.Input);
// Set a debounce timeout to filter out switch bounce noise from a button press
buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
// Register for the ValueChanged event so our buttonPin_ValueChanged
// function is called when the button is pressed
buttonPin.ValueChanged += buttonPin_ValueChanged;
Debug.WriteLine("GPIO pins initialized correctly.");
}
private void buttonPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs e)
{
// toggle the state of the LED every time the button is pressed
if (e.Edge == GpioPinEdge.FallingEdge)
{
ledPinValue = (ledPinValue == GpioPinValue.Low) ?
GpioPinValue.High : GpioPinValue.Low;
ledPin.Write(ledPinValue);
}
}
}
}`
The text was updated successfully, but these errors were encountered:
Sign up for freeto subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Hello,
when I use BackgroundApp (IoT) template I get no values from the pins.
I try it exactly as in Foreground App, but there is no event triggered when pressing the button.
Can someone tell me what I do wrong?
Here is my Code
`namespace BackgroundApplication2
{
public sealed class StartupTask : IBackgroundTask
{
private const int LED_PIN = 6;
private const int BUTTON_PIN = 5;
private GpioPin ledPin;
private GpioPin buttonPin;
private GpioPinValue ledPinValue = GpioPinValue.High;
}`
The text was updated successfully, but these errors were encountered: