We no longer sell products directly from the GHI Electronics website, click here for more details. Please find a Distributor to complete your online order. If you have any questions regarding this notice please contact us at support@ghielectronics.com.

Digital Outputs

Last modified August 20, 2014

Required

Tutorials:  First NETMF Project, Locating IOs

Introduction

A digital output pin can be set to either high or low. There are different ways of describing these two states. High can also be called "true" or "one;" low can be called "false" or "zero".

If the processor is powered off of 3.3 V, then the state high means that there is 3.3 V on the output pin. It is not going to be exactly 3.3 V but very close. When the pin is set to low then it is voltage is very close to zero volts.

Warning

Never connect two output pins together. If they are connected and one is high and the other is low, the entire processor can be damaged.

The digital pins on micro-controllers are very weak. They can not be used to drive devices that require a lot of power.

Tip

All the examples shown below require the Microsoft.SPOT.Hardware assembly. Consult the device schematics or manual for specific pin numbers.

Light Up an LED

This example turns a LED on. The initial state of the pin, true or false, must be specified when creating the OutputPort. This example makes the pin true which will cause the LED be on by default.

using System.Threading;
using Microsoft.SPOT.Hardware;


public class Program
{
    public static void Main()
    {
        OutputPort LED;
        LED = new OutputPort(Cpu.Pin.GPIO_Pin1, true);

        Thread.Sleep(Timeout.Infinite);
    }
}

Blink an LED

To blink an LED, the pin is toggled between high and low. Due to the high speed of the micro-controller (flashes the LED millions of times per second), a delay needs to be added between ON and OFF to see the blinking.

 

using System.Threading;
using Microsoft.SPOT.Hardware;

public class Program
{
    public static void Main()
    {
        OutputPort LED;
        LED = new OutputPort(Cpu.Pin.GPIO_Pin1, true);

        while (true)
        {
            LED.Write(!LED.Read());
            Thread.Sleep(200);
        }
    }
}
Leave feedback about this document.
Let us know if the information presented here was accurate, helpful and if you have any suggestions.
Leave feedback about this document.
Let us know if the information presented here was accurate, helpful and if you have any suggestions.

* Indicates required fields.
This form is only for feedback not support.
Review our how to find information guide on locating helpful resources.