本文整理汇总了C#中Windows.Devices.Gpio.GpioPin.Read方法的典型用法代码示例。如果您正苦于以下问题:C# GpioPin.Read方法的具体用法?C# GpioPin.Read怎么用?C# GpioPin.Read使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Windows.Devices.Gpio.GpioPin
的用法示例。
在下文中一共展示了GpioPin.Read方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: ValueChangedHandler
private void ValueChangedHandler(GpioPin sender, GpioPinValueChangedEventArgs args)
{
var pinNumber = sender.PinNumber;
var gpioPinValue = sender.Read();
Debug.WriteLine("Pin {0} changed to {1}", pinNumber, gpioPinValue);
if (pinNumber == TiltSensorPin)
{
_halper.DishwasherTilt(gpioPinValue == GpioPinValue.High);
var currentStatus = _halper.Get().CurrentStatus;
if (currentStatus == DishwasherStatus.Clean && gpioPinValue == GpioPinValue.High)
{
ThreadPoolTimer.CreatePeriodicTimer(Timer_Tick, TimeSpan.FromMilliseconds(10000));
}
return;
}
var tiltSensorValue = _gpioSensors[TiltSensorPin].Read();
if (gpioPinValue == GpioPinValue.High)
{
if (pinNumber == CleanLightPin)
{
_halper.EndDishwasherRun();
}
else if (tiltSensorValue == GpioPinValue.Low && _pinToCycleTypeMap.ContainsKey(pinNumber))
{
_halper.StartDishwasherRun(_pinToCycleTypeMap[pinNumber]);
}
}
}
示例2: InitGPIO
private void InitGPIO()
{
var mygpio = GpioController.GetDefault();
// Show an error if there is no GPIO controller
if (mygpio == null)
{
buttonPin = null;
ledPin = null;
return;
}
ledPin = mygpio.OpenPin(LEDPINNBR);
ledPin.Write(GpioPinValue.Low); //initialize Led to On as wired in active Low config (+3.3-Led-GPIO)
ledPin.SetDriveMode(GpioPinDriveMode.Output);
buttonPin = mygpio.OpenPin(BUTTONPINNBR);
//buttonPin.Write(GpioPinValue.High);
//buttonPin.SetDriveMode(GpioPinDriveMode.Output);
//buttonPinValCurrent = buttonPin.Read();
buttonPin.SetDriveMode(GpioPinDriveMode.Input);
//buttonPinValPrior = GpioPinValue.High;
Debug.WriteLine("ButtonPin Value at Init: " + buttonPin.Read() + ", with Pin ID = " + buttonPin.PinNumber);
//buttonPinVal = buttonPin.Read();
// Set a debounce timeout to filter out switch bounce noise from a button press
buttonPin.DebounceTimeout = TimeSpan.FromMilliseconds(20);
// Register for the ValueChanged event so our buttonPin_ValueChanged
// function is called when the button is pressed
buttonPin.ValueChanged += buttonPressAction;
}
示例3: ButtonPin_ValueChanged
private void ButtonPin_ValueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
{
if (sender.Read() == GpioPinValue.High)
{
sendEvents = !sendEvents;
if (sendEvents)
{
Task.Run(() => SendEvents());
}
}
}
示例4: FlipLed
private void FlipLed(GpioPin led)
{
if (adcValue == 0)
{
turnOnLed(led);
return;
}
if (led.Read() == GpioPinValue.High)
turnOnLed(led);
else
turnOffLed(led);
}
示例5: RCTime
int RCTime(GpioPin pin, int max)
{
pin.SetDriveMode(GpioPinDriveMode.Output);
pin.Write(GpioPinValue.Low);
pin.SetDriveMode(GpioPinDriveMode.Input);
int reading = 0;
while (pin.Read() == GpioPinValue.Low)
{
reading++;
if (reading >= max) break;
}
return reading;
}
示例6: InitalizeLed
public void InitalizeLed()
{
Debug.WriteLine("InternetLed::InitalizeLed");
// Now setup the LedControlPin
gpio = GpioController.GetDefault();
LedControlGPIOPin = gpio.OpenPin(LedControlPin);
LedControlGPIOPin.SetDriveMode(GpioPinDriveMode.Output);
// Get the current pin value
GpioPinValue startingValue = LedControlGPIOPin.Read();
_LedState = (startingValue == GpioPinValue.Low) ? eLedState.On : eLedState.Off;
}
示例7: PulseIn
private double PulseIn(GpioPin pin, GpioPinValue value, ushort timeout)
{
sw.Restart();
// Wait for pulse
while (sw.ElapsedMilliseconds < timeout && pin.Read() != value) {}
if (sw.ElapsedMilliseconds >= timeout)
{
sw.Stop();
return 0;
}
sw.Restart();
// Wait for pulse end
while (sw.ElapsedMilliseconds < timeout && pin.Read() == value) { }
sw.Stop();
return sw.ElapsedMilliseconds < timeout ? sw.Elapsed.TotalMilliseconds : 0;
}
示例8: InitGpio
/// <summary>
/// Initialize GPIO pins
/// Initialise les pin GPIO
/// </summary>
private void InitGpio()
{
var gpio = GpioController.GetDefault();
_echoPin = gpio.OpenPin(ECHO_PIN);
_triggerPin = gpio.OpenPin(TRIGGER_PIN);
_echoPin.SetDriveMode(GpioPinDriveMode.Input);
_triggerPin.SetDriveMode(GpioPinDriveMode.Output);
_triggerPin.Write(GpioPinValue.Low);
var value = _triggerPin.Read();
}
示例9: KEYoneDown
private void KEYoneDown(GpioPin gpioPin, GpioPinValueChangedEventArgs e)
{
if (gpioPin.Read() == GpioPinValue.Low)
{
Debug.WriteLine("LED ON");
pinLed.Write(GpioPinValue.High);
DistanceReading();
}
else
{
pinLed.Write(GpioPinValue.Low);
}
}
示例10: VoiceDete
private void VoiceDete(GpioPin gpioPin, GpioPinValueChangedEventArgs e)
{
if (gpioPin.Read() == GpioPinValue.Low)
{
Debug.WriteLine("VoiceDete");
DistanceReading();
}
}
示例11: PulseIn
private double PulseIn(GpioPin pin, GpioPinValue value, ushort timeout)
{
var sw = new Stopwatch();
var sw_timeout = new Stopwatch();
sw_timeout.Start();
// Wait for pulse
while (pin.Read() != value)
{
if (sw_timeout.ElapsedMilliseconds > timeout)
return 3.5;
}
sw.Start();
// Wait for pulse end
while (pin.Read() == value)
{
if (sw_timeout.ElapsedMilliseconds > timeout)
return 3.4;
}
sw.Stop();
return sw.Elapsed.TotalSeconds;
}
示例12: valueChanged
private void valueChanged(GpioPin sender, GpioPinValueChangedEventArgs args)
{
var t = Dispatcher.RunAsync(Windows.UI.Core.CoreDispatcherPriority.High, () =>
{
if (sender.Read().ToString().ToLower() == "low")
{
uiGpioMap["GPIO_" + sender.PinNumber].Foreground = new SolidColorBrush(Colors.Red);
}
else
{
uiGpioMap["GPIO_" + sender.PinNumber].Foreground = new SolidColorBrush(Colors.Green);
}
uiGpioMap["GPIO_" + sender.PinNumber].Text = sender.Read().ToString();
});
}
示例13: LeftIRLine
/*
/// <summary>
/// LeftIRLine reads the current value
/// of the left IR line sensor
/// </summary>
public static bool LeftIRLine()
{
GpioPinValue pinVal = flIRLinePin.Read();
if (pinVal == 0)
{
return true;
}
else
{
return false;
}
} // end LeftIRLine
/// <summary>
/// RightIRLine reads the current value
/// of the right IR line sensor
/// </summary>
public static bool RightIRLine()
{
GpioPinValue pinVal = frIRLinePin.Read();
if (pinVal == 0)
{
return true;
}
else
{
return false;
}
} // end RightIRLine
*/
//*******************************//
//*** SETUP ULTRASONIC SENSOR ***//
//*******************************//
/// <summary>
/// getElapsedTime uses the ultrasonic sensor to
/// send out a pulse and records the time it
/// takes to be read back in by the sensor
/// </summary>
public static decimal GetElapsedTime()
{
decimal start = 0.00m;
decimal stop = 0.00m;
Stopwatch count = new Stopwatch();
long seed = Environment.TickCount;
sonarPin = gpioController.OpenPin(SONAR_PIN);
sonarPin.SetDriveMode(GpioPinDriveMode.Output);
sonarPin.Write(GpioPinValue.Low);
new System.Threading.ManualResetEvent(false).WaitOne(10); // pause thread for 10 microseconds
sonarPin.Write(GpioPinValue.High);
count.Start();
sonarPin.SetDriveMode(GpioPinDriveMode.Input);
GpioPinValue sonarVal = sonarPin.Read();
while (sonarVal == 0 && count.ElapsedMilliseconds < 100)
{
start = DateTime.Now.Ticks / (decimal)TimeSpan.TicksPerMillisecond;
sonarVal = sonarPin.Read(); // update sonarVal
}
count.Restart();
while (sonarVal != 0 && count.ElapsedMilliseconds < 100)
{
stop = DateTime.Now.Ticks / (decimal)TimeSpan.TicksPerMillisecond;
sonarVal = sonarPin.Read(); // update sonarVal
}
decimal elapsedTime = stop - start;
decimal etSec = elapsedTime * 0.001m; // convert elapsedTime from milliseconds to seconds
return etSec;
/* IMPLEMENTATION NOTE:
* To get a distance value, multiply the return value (etSec)
* by the time it takes the signal to reach a target and return
* (e.g. etSec * 34000 = cm/s). Then divide that value by
* two to get the distance between the bot and a particular object
*/
}
示例14: StartMonitoring
private void StartMonitoring()
{
this.txtOutput.Text = string.Empty;
this.txtOutput.Text = DateTime.Now.Ticks.ToString() + "\n";
var gpio = GpioController.GetDefault();
//setPin = gpio.OpenPin(SET_PIN);
_clockPin = gpio.OpenPin(CLOCK_PIN);
_dataPin = gpio.OpenPin(DATA_PIN);
//_clockPin.SetDriveMode(GpioPinDriveMode.Output);
//_dataPin.SetDriveMode(GpioPinDriveMode.Input);
//byte data[3];
//// pulse the clock pin 24 times to read the data
//for (byte j = 3; j--;)
//{
// for (char i = 8; i--;)
// {
// digitalWrite(PD_SCK, HIGH);
// bitWrite(data[j], i, digitalRead(DOUT));
// digitalWrite(PD_SCK, LOW);
//}
//for (byte j = 3; j <= 0; j--) {
// this.txtOutput.Text += "j " + j.ToString() + "\n";
//}
var c = 0;
for (int j = 2; j >= 0; j--)
{
this.txtOutput.Text += "Byte:" + j + "\n";
for (int i = 7; i >= 0; i--)
{
_clockPin.Write(GpioPinValue.High);
var dataPinValue = _dataPin.Read();
_clockPin.Write(GpioPinValue.Low);
if (dataPinValue == GpioPinValue.Low)
{
var yay = true;
}
this.txtOutput.Text += dataPinValue + "\n";
c++;
}
}
// Release the GPIO pins.
if (_dataPin != null)
{
_dataPin.Dispose();
_dataPin = null;
}
if (_clockPin != null)
{
_clockPin.Dispose();
_clockPin = null;
}
}
示例15: InitGpio
public async void InitGpio()
{
gpioController = GpioController.GetDefault();
try
{
switchPin1 = gpioController.OpenPin(switchPinNum1);
switchPin2 = gpioController.OpenPin(switchPinNum2);
switchPin1.SetDriveMode(GpioPinDriveMode.Input);
switchPin2.SetDriveMode(GpioPinDriveMode.Input);
GpioPinValue v1 = switchPin1.Read();
GpioPinValue v2 = switchPin2.Read();
////Set Initial
//if (switchPin1.Read() == GpioPinValue.Low)
//{
// selectedLang = en_lang;
// //selectedLang = ch_lang;
//}
//else
//{
// selectedLang = ch_lang;
//}
// selectLang();
await startSRProcess();
switchPin1.DebounceTimeout = new TimeSpan(0, 0, 0, 1, 0);
// value change
switchPin1.ValueChanged += async (s, e) =>
{
if (isListening)
{
try
{
await speechRecognizer.ContinuousRecognitionSession.StopAsync();
}
catch
{
}
}
// await selectLang();
await startSRProcess();
};
}
catch (Exception ex)
{
}
}