我目前正在使用c#制作一个覆盆子pi机器人车的东西。我完全没有C#的知识,所以这是我学习它的方式。GPIO在树莓派c#
汽车使用L298N来控制电机,所以我需要弄清楚如何让pi从一个引脚输出高电平,然后从另一个引脚输出低电平,然后我可以制定如何控制它。
但重点是,我写了一些代码,希望它会激活其中一个电机,但似乎并不如此。我希望能够更好地理解c#和GPIO引脚的人能够指出错误。
感谢,卡勒姆
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using Windows.Devices.Gpio;
// The Blank Page item template is documented at http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409
namespace App4
{
/// <summary>
/// An empty page that can be used on its own or navigated to within a Frame.
/// </summary>
public sealed partial class MainPage : Page
{
public void GPIO()
{
GpioController gpio = GpioController.GetDefault();
if (gpio == null)
return;
using (GpioPin pin1 = gpio.OpenPin(5))
{
pin1.Write(GpioPinValue.High);
pin1.SetDriveMode(GpioPinDriveMode.Output);
}
using (GpioPin pin2 = gpio.OpenPin(6))
{
pin2.Write(GpioPinValue.Low);
pin2.SetDriveMode(GpioPinDriveMode.Output);
}
}
}
}
我对C#没有任何关于GPIO的知识,但是您可能想在写入之前先调用SetDriveMode输出,对吗? – MrZander