LoginSignup
2
3

More than 5 years have passed since last update.

Windows10 IoTCore プログラム サンプル Lピカ (No.001)

Last updated at Posted at 2017-01-01

Windows10IoTCore+RaspberryPi3向けサンプルプログラム(RaspberryPi2でも動作します)

Build 14393で動作確認しています。

LEDを点灯する

GPIO5にLEDを接続して点灯させる。
配線などはこちらもしくはApplePi等の拡張ボードを利用する。
phC-BTO-300x274.png

プログラム

MainPage.xaml
<Page
    x:Class="_001_LED.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:_001_LED"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    mc:Ignorable="d" Unloaded="Page_Unloaded">

    <Grid Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">

    </Grid>
</Page>
MainPage.xaml.cs
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;

using Windows.Devices.Gpio;

// 空白ページのアイテム テンプレートについては、http://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x409 を参照してください

namespace _001_LED
{
    /// <summary>
    /// それ自体で使用できる空白ページまたはフレーム内に移動できる空白ページ。
    /// </summary>
    public sealed partial class MainPage : Page
    {
        private GpioPin pin = null;

        /// <summary>
        /// 
        /// </summary>
        public MainPage()
        {
            this.InitializeComponent();

            Led_On();
        }

        /// <summary>
        /// 
        /// </summary>
        private void Led_On()
        {
            var gpio = GpioController.GetDefault();             //GPIOコントローラーの取得

            if (gpio != null)
            {
                pin = gpio.OpenPin(5);                          //GPIO5を使用
                pin.Write(GpioPinValue.High);                   //GPIO5をHigh(オンにする)
                pin.SetDriveMode(GpioPinDriveMode.Output);      //GPIO5を出力モードにする
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void Page_Unloaded(object sender, RoutedEventArgs e)
        {
            //終了処理
            pin.Dispose();
        }
    }
}

LEDが点灯するだけのプログラム

プロジェクトはこちらからダウンロードできます。

2
3
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
3