티스토리 뷰

라즈베리파이에서 윈동우 IOT 어렵다. 


포기한다. 


LED 점멸, 깜박이는것 만드는데도 왜이리 복잡스러운지 

비주얼스튜디오에 윈도우iot를 설치해줘야 합니다. 

비주얼스튜디오에서 윈도우 iot 설치방법은 간단합니다. 

도구->확장 및 업데이트->온라인->검색란에 windows iot를 입력

그리고 windows iot core templates for vs 2017를 설치하면 끝입니다. 


ㅁㅁㅁ

 
visual c# 에서 windows유니버설 선택후 비어있는앱으로 시작합니다.


위에 그림처럼 x86을 ARM으로 변경하고 그 옆에도 원격컴퓨터로 변경합니다. 그리고 라즈베리파이 ip주소도 넣어줍니다. 라즈베리파이 ip주소는 ifconfig로 확인할 수 있습니다. 


ㅁㅁㅁ

그럼 MainPage.xaml 과 MainPage.xmal.cs만 코딩하면 됩니다. 

MainPage.xaml에 가서 <Grid> 사이에 다음과 같은 코드를 삽입합니다. 

 <StackPanel HorizontalAlignment="Center" VerticalAlignment="Center">

            <Ellipse x:Name="LED" Fill="LightGray" Stroke="White" Width="100" Height="100" Margin="10"/>

            <TextBlock x:Name="GpioStatus" Text="Waiting to initialize GPIO..." Margin="10,50,10,10" TextAlignment="Center" FontSize="26.667" />

        </StackPanel>


그럼 위의 그림과 같이 원모양이 생겨요. 

ㅁㅁㅁ


MainPage.xmal.cs 에는 다음과 같은 코드를 넣습니다. 

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;


// 빈 페이지 항목 템플릿에 대한 설명은 https://go.microsoft.com/fwlink/?LinkId=402352&clcid=0x412에 나와 있습니다.


namespace App1

{

    /// <summary>

    /// 자체적으로 사용하거나 프레임 내에서 탐색할 수 있는 빈 페이지입니다.

    /// </summary>

    public sealed partial class MainPage : Page

    {

        private const int PIN_NUM = 5;

        private GpioPin pin;

        private GpioPinValue pinValue;

        private DispatcherTimer timer;

        private SolidColorBrush redBrush = new SolidColorBrush(Windows.UI.Colors.Red);

        private SolidColorBrush grayBrush = new SolidColorBrush(Windows.UI.Colors.LightGray);


        public MainPage()

        {

            this.InitializeComponent();


            InitTimer();

            InitGPIO();


            if (null != pin)

            {

                timer.Start();

            }


        }


        private void InitTimer(int interval = 500)

        {

            timer = new DispatcherTimer();

            timer.Interval = TimeSpan.FromMilliseconds(interval);

            timer.Tick += Timer_Tick;

        }


        private void InitGPIO()

        {

            var gpio = GpioController.GetDefault();


            if (null == gpio)

            {

                GpioStatus.Text = "There is no GPIO controller on this device.";

                return;

            }


            pin = gpio.OpenPin(PIN_NUM);

            pinValue = GpioPinValue.High;

            pin.Write(pinValue);

            pin.SetDriveMode(GpioPinDriveMode.Output);


            GpioStatus.Text = "GPIO pin initialized correctly.";

        }


        private void Timer_Tick(object sender, object e)

        {

            if (GpioPinValue.High == pinValue)

            {

                pinValue = GpioPinValue.Low;

                pin.Write(pinValue);

                LED.Fill = redBrush;

            }

            else

            {

                pinValue = GpioPinValue.High;

                pin.Write(pinValue);

                LED.Fill = grayBrush;

            }

        }

    }

}


스타트 버튼(원격 컴퓨터)을 눌러서 컴파일합니다. 


ㅁㅁㅁ

위와 같이 LED점멸 완성 

어렵다. 그냥 라즈비안으로 넘어가야지 (사실 이 간단한것 하는데도 우여곡절이 많았아요.)

'프로그래밍 > C#' 카테고리의 다른 글

맥에 MySQL 설치하기  (0) 2018.09.20
MinnowBoard Max Pin Mappings  (0) 2018.08.23
드래곤 보드 핀 매핑(Dragonboard Pin Mappings)  (0) 2018.08.23
Raspberry Pi 2 & 3 Pin Mappings  (0) 2018.08.23
하드웨어 호환성 목록  (0) 2018.08.23
댓글
최근에 달린 댓글
글 보관함
«   2024/05   »
1 2 3 4
5 6 7 8 9 10 11
12 13 14 15 16 17 18
19 20 21 22 23 24 25
26 27 28 29 30 31
Total
Today
Yesterday
    뽀로로친구에디
    최근에 올라온 글