Netduino 2 Lチカ 4LED点灯基本(Arduino 用の multifunction シールドを使う)

Netduino 2 (Visual Studio 2015 C#) に「Arduino UNO R3 学習向け多機能拡張シールド」を取り付けて動作検証をしています。

 

今回は、シールドについている4個のLEDを流れるような点灯の動作実験に試みた。

4個のボタンのポートを調べた結果、アナログポート 「GPIO_PIN_D10_D11,D12,D13」を使用しています。

Visual Studio 2015 C# のソース記述

NetduinoApplication4

 

using System;
using System.Net;
using System.Net.Sockets;
using System.Threading;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using SecretLabs.NETMF.Hardware;
using SecretLabs.NETMF.Hardware.Netduino;

namespace NetduinoApplication4
{
    public class Program
    {
        public static void Main()
        {
            // write your code here
            // シールドLEDの設定
            OutputPort boardLed01 = new OutputPort(Pins.GPIO_PIN_D10, false);
            OutputPort boardLed02 = new OutputPort(Pins.GPIO_PIN_D11, false);
            OutputPort boardLed03 = new OutputPort(Pins.GPIO_PIN_D12, false);
            OutputPort boardLed04 = new OutputPort(Pins.GPIO_PIN_D13, false);

            // LED点滅は別スレッドで実行
            new Thread(() =>
            {
                while (true)
                {
                    boardLed01.Write(false);
                    Thread.Sleep(100);
                    boardLed01.Write(true);
                    Thread.Sleep(100);
                    boardLed02.Write(false);
                    Thread.Sleep(100);
                    boardLed02.Write(true);
                    Thread.Sleep(100);
                    boardLed03.Write(false);
                    Thread.Sleep(100);
                    boardLed03.Write(true);
                    Thread.Sleep(100);
                    boardLed04.Write(false);
                    Thread.Sleep(100);
                    boardLed04.Write(true);
                    Thread.Sleep(100);
                }
            }).Start();

            // メインスレッドを終了させるとプログラムが終了するので無限に停止
            Thread.Sleep(Timeout.Infinite);
        }

    }
}

 

目 次