本文整理汇总了C#中Windows.Devices.Gpio.GpioPin.Write方法的典型用法代码示例。如果您正苦于以下问题:C# GpioPin.Write方法的具体用法?C# GpioPin.Write怎么用?C# GpioPin.Write使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Devices.Gpio.GpioPin
的用法示例。
在下文中一共展示了GpioPin.Write方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: InitAsync
public async Task InitAsync()
{
if (!init)
{
var gpio = GpioController.GetDefault();
if (gpio != null)
{
gpioPinTrig = gpio.OpenPin(trigGpioPin);
gpioPinEcho = gpio.OpenPin(echoGpioPin);
gpioPinTrig.SetDriveMode(GpioPinDriveMode.Output);
gpioPinEcho.SetDriveMode(GpioPinDriveMode.Input);
gpioPinTrig.Write(GpioPinValue.Low);
//first time ensure the pin is low and wait two seconds
gpioPinTrig.Write(GpioPinValue.Low);
await Task.Delay(2000);
init = true;
}
else
{
throw new InvalidOperationException("Gpio not present");
}
}
}
示例2: TLC5947ControllerBase
//
// Constructor
//
public TLC5947ControllerBase(uint latchPin, uint blackoutPin)
{
// Create the controller
m_controller = new LedController(this, ControlerUpdateType.AllSlots);
// Open the latch pin
GpioController controller = GpioController.GetDefault();
m_latchPin = controller.OpenPin((int)latchPin);
m_latchPin.SetDriveMode(GpioPinDriveMode.Output);
// Open the black out pin, set it high and low to reset the device.
m_blackoutPin = controller.OpenPin((int)blackoutPin);
m_blackoutPin.SetDriveMode(GpioPinDriveMode.Output);
m_blackoutPin.Write(GpioPinValue.High);
m_blackoutPin.Write(GpioPinValue.Low);
// Create a async task to setup SPI
new Task(async () =>
{
// Create the settings
var settings = new SpiConnectionSettings(SPI_CHIP_SELECT_LINE);
// Max SPI clock frequency, here it is 30MHz
settings.ClockFrequency = 30000000;
settings.Mode = SpiMode.Mode0;
// Find the selector string for the SPI bus controller
string spiAqs = SpiDevice.GetDeviceSelector(SPI_CONTROLLER_NAME);
// Find the SPI bus controller device with our selector string
var devicesInfo = await DeviceInformation.FindAllAsync(spiAqs);
// Create an SpiDevice with our bus controller and SPI settings
m_spiDevice = await SpiDevice.FromIdAsync(devicesInfo[0].Id, settings);
}).Start();
}
示例3: Configure
public void Configure(GpioPin gpioPin)
{
_gpioPin = gpioPin;
// init the pin
_gpioPin.SetDriveMode(GpioPinDriveMode.Output);
_gpioPin.Write(GpioPinValue.High);
_gpioPin.Write(GpioPinValue.Low);
_gpioPin.Write(GpioPinValue.High);
}
示例4: Zone
public Zone(string id, GpioPin pin)
{
_id = id;
_pin = pin;
_pin.Write(GpioPinValue.Low);
_pin.SetDriveMode(GpioPinDriveMode.Output);
_pin.Write(GpioPinValue.High);
_state = OFF_STATE;
}
示例5: Initialize
public void Initialize()
{
var gpioController = GpioController.GetDefault();
_mosiPin = gpioController.OpenPin(_mosi);
_misoPin = gpioController.OpenPin(_miso);
_clkPin = gpioController.OpenPin(_clk);
_csPin = gpioController.OpenPin(_cs);
_mosiPin.Write(GpioPinValue.Low);
_mosiPin.Write(GpioPinValue.Low);
_clkPin.Write(GpioPinValue.Low);
_csPin.Write(GpioPinValue.High);
}
示例6: InitGPIO
private void InitGPIO()
{
var gpio = GpioController.GetDefault();
// error prompt
if (gpio == null) {
GpioStatus.Text = "There's no GPIO controller on this device";
return -1;
}
buttonPin = gpio.OpenPin(BUTTON_PIN);
ledPin = gpio.OpenPin(LED_PIN);
// init LED to OFF by HIGH, cuz LED is wired in LOW config
ledPin.Write(GpioPinValue.High);
ledPin.SetDriveMode(GpioPinDriveMode.Output);
// checking if input pull-up resistors are supported
if (buttonPin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp)) {
buttonPin.SetDriveMode(GpioPinDriveMode.InputPullUp);
}
else {
buttonPin.SetDriveMode(GpioPinDriveMode.Input);
}
// setting debounce timeout
buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
// register for ValueChanged event
// so buttonPin_ValueChanged()
// is called when button is pressed
buttonPin.ValueChanged += buttonPin_ValueChanged;
GpioStatus.Text = "GPIO pins initialized correctly";
}
示例7: InitGPIO
private void InitGPIO()
{
if (!ApiInformation.IsTypePresent(GpioPresentNS))
{
return;
}
var gpio = GpioController.GetDefault();
if (gpio == null)
{
Debug.WriteLine("There is no GPIO controller on this device.");
return;
}
var buttonPin = gpio.OpenPin(ButtonPin);
ledPin = gpio.OpenPin(LedPin);
// 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(100);
buttonPin.ValueChanged += ButtonPin_ValueChanged;
}
示例8: InitGPIO
private void InitGPIO()
{
// get the GPIO controller
var gpio = GpioController.GetDefault();
// return an error if there is no gpio controller
if (gpio == null)
{
led = null;
GpioStatus.Text = "There is no GPIO controller.";
return;
}
// set up the LED on the defined GPIO pin
// and set it to High to turn off the LED
led = gpio.OpenPin(ledPin);
led.Write(GpioPinValue.High);
led.SetDriveMode(GpioPinDriveMode.Output);
// set up the PIR sensor's signal on the defined GPIO pin
// and set it's initial value to Low
pir = gpio.OpenPin(pirPin);
pir.SetDriveMode(GpioPinDriveMode.Input);
//ID is the Pin number
sensor1.SensorId = pir.PinNumber.ToString();
sensor1.SensorType = "PIR";
sensors[node1.CurrentSensor] = sensor1;
GpioStatus.Text = "GPIO pins initialized correctly.";
}
示例9: InitGPIO
private void InitGPIO()
{
_pin = GpioController.GetDefault().OpenPin(_pinNumber);
_pin.Write(GpioPinValue.High);
_pin.SetDriveMode(GpioPinDriveMode.Output);
}
示例10: InitGPIO
private void InitGPIO()
{
var gpio = GpioController.GetDefault();
// Show an error if there is no GPIO controller
if (gpio == null)
{
pin = null;
Debug.WriteLine("There is no GPIO controller on this device.");
return;
}
pin = gpio.OpenPin(LED_PIN);
// Show an error if the pin wasn't initialized properly
if (pin == null)
{
Debug.WriteLine("There is no GPIO controller on this device.");
return;
}
pin.Write(GpioPinValue.High);
pin.SetDriveMode(GpioPinDriveMode.Output);
Debug.WriteLine("There is no GPIO controller on this device.");
}
示例11: StartScenario
void StartScenario()
{
// Initialize the GPIO objects.
var gpio = GpioController.GetDefault();
// Set up our GPIO pin for setting values.
// If this next line crashes with a NullReferenceException,
// then the problem is that there is no GPIO controller on the device.
setPin = gpio.OpenPin(SET_PIN);
// Establish initial value and configure pin for output.
setPin.Write(currentValue);
setPin.SetDriveMode(GpioPinDriveMode.Output);
// Set up our GPIO pin for listening for value changes.
listenPin = gpio.OpenPin(LISTEN_PIN);
// Configure pin for input and add ValueChanged listener.
listenPin.SetDriveMode(GpioPinDriveMode.Input);
listenPin.ValueChanged += Pin_ValueChanged;
// Start toggling the pin value every 500ms.
timer = new DispatcherTimer();
timer.Interval = TimeSpan.FromMilliseconds(500);
timer.Tick += Timer_Tick;
timer.Start();
}
示例12: OutputPin
public OutputPin(int pinNumber, string name)
: base(name, "output")
{
pin = gpio.OpenPin((int)pinNumber, GpioSharingMode.Exclusive);
pin.SetDriveMode(GpioPinDriveMode.Output);
pin.Write(GpioPinValue.Low);
}
示例13: InitGPIO
public bool InitGPIO()
{
//compiler directive to check whether it's running on the correct system.
#if NETFX_CORE
var gpio = GpioController.GetDefault();
if (gpio == null)
{
pin = null;
status = "There is no GPIO controller on this device";
return false;
}
//If you have an LED on pin 2 - otherwise change the number
pin = gpio.OpenPin(2);
//make sure the pin has been initialised correctly
if (pin == null)
{
status = "There was a problem initialising the GPIO Pin";
return false;
}
pin.Write(GpioPinValue.High);
pin.SetDriveMode(GpioPinDriveMode.Output);
status = "GPIO pin is set correctly";
return true;
#else
status = "NO GPIO Hardware";
return true;
#endif
}
示例14: RGBLed
public RGBLed(int redPin, int greenPin, int bluePin)
{
var gpio = GpioController.GetDefault();
if (gpio == null) throw new RGBLedException(RGBLedError.E_GPIO_NOT_FOUND);
try
{
m_redPin = gpio.OpenPin(redPin);
m_greenPin = gpio.OpenPin(greenPin);
m_bluePin = gpio.OpenPin(bluePin);
m_redPin.Write(GpioPinValue.Low);
m_redPin.SetDriveMode(GpioPinDriveMode.Output);
m_greenPin.Write(GpioPinValue.Low);
m_greenPin.SetDriveMode(GpioPinDriveMode.Output);
m_bluePin.Write(GpioPinValue.Low);
m_bluePin.SetDriveMode(GpioPinDriveMode.Output);
}
catch(Exception ex)
{
throw new RGBLedException(RGBLedError.E_OPEN_PIN_ERROR, ex);
}
}
示例15: InitGPIO
private void InitGPIO()
{
var gpio = GpioController.GetDefault();
// Show an error if there is no GPIO controller
if (gpio == null)
{
_buttonpin = null;
_buzzerpin = null;
GpioStatus.Text = "There is no GPIO controller on this device.";
return;
}
_buttonpin = gpio.OpenPin(BUTTON_PIN);
_buzzerpin = gpio.OpenPin(BUZZER_PIN);
if (_buttonpin.IsDriveModeSupported(GpioPinDriveMode.InputPullUp))
_buttonpin.SetDriveMode(GpioPinDriveMode.InputPullUp);
else
_buttonpin.SetDriveMode(GpioPinDriveMode.Input);
_buttonpin.DebounceTimeout = TimeSpan.FromMilliseconds(50);
_buttonpin.ValueChanged += Buttonpin_ValueChanged;
_buzzerpin.Write(GpioPinValue.Low);
_buzzerpin.SetDriveMode(GpioPinDriveMode.Output);
GpioStatus.Text = "GPIO button and buzzer pin initialized correctly.";
}