How to use the LED of the FEZ Mini Robot

This also applies to the E-block button.
If you have the LED on an output port connected and has the value true (not burn) then I’m a little scared of the 220 Ohm resistor by pushbutton can be connected to ground.

My solution is to port as TriState to define the initial value of false and resistormode disabled.
Switching the LED is done by the TriStatePort to switch from input to output, etc.

I was also provides that the power may be too high but that turned out to be 3.6 mA, so just within the max value of 4 mA per pin.

Is my conclusion correct? you in this way, the LED can be used without problems.


using System;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;

namespace FEZ_Mini_Show_Sensors
{
    public class Program
    {
        public static void Main()
        {
            TristatePort LedLeft = new TristatePort((Cpu.Pin)FEZ_Pin.Digital.Di4, false, false, Port.ResistorMode.Disabled);
            TristatePort LedRight = new TristatePort((Cpu.Pin)FEZ_Pin.Digital.Di2, false, false, Port.ResistorMode.Disabled);
            if (LedLeft.Active) 
                LedLeft.Active = false;  // set port to input
            if (LedRight.Active)
                LedRight.Active = false;
            // Create ReflectiveSensor object assigned to the Reflective Sensor Component connected to An6 and An7
            // Reflection detection trigger is on 70% or more.
            FEZ_Components.ReflectiveSensor myReflectiveSensorLeft = new FEZ_Components.ReflectiveSensor(FEZ_Pin.AnalogIn.An7, 70);
            FEZ_Components.ReflectiveSensor myReflectiveSensorRight = new FEZ_Components.ReflectiveSensor(FEZ_Pin.AnalogIn.An6, 70);

            while (true)
            {
                if (myReflectiveSensorLeft.GetState() != FEZ_Components.ReflectiveSensor.DetectingState.ReflectionDeteced) // black detected
                {
                    if (LedLeft.Active == false)
                        LedLeft.Active = true;
                }
                else
                {
                    if (LedLeft.Active == true)
                        LedLeft.Active = false;
                }

                if (myReflectiveSensorRight.GetState() != FEZ_Components.ReflectiveSensor.DetectingState.ReflectionDeteced) // black detected
                {
                    if (LedRight.Active == false)
                        LedRight.Active = true;
                }
                else
                {
                    if (LedRight.Active == true)
                        LedRight.Active = false;
                }
                Thread.Sleep(100);
            }
        }
    }
}

With the test program, the LED is lit when the reflective sensor detects black

I have GHI Button class converted to Led_Button class
You can now either use the button and the led, unfortunately, an interrupt is not supported by the TriState port so this option has expired

In the test program, the LED controlled by the reflective sensor and the button gives a beep.

the test program


using System;
using System.Threading;

using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;

using GHIElectronics.NETMF.FEZ;

namespace FEZ_Mini_Show_Sensors
{
    public class Program
    {
        public static void Main()
        {
            FEZ_Components.ReflectiveSensor myReflectiveSensorLeft = new FEZ_Components.ReflectiveSensor(FEZ_Pin.AnalogIn.An7, 50);
            FEZ_Components.ReflectiveSensor myReflectiveSensorRight = new FEZ_Components.ReflectiveSensor(FEZ_Pin.AnalogIn.An6, 50);

            FEZ_Components.Led_Button myLedButtonLeft = new FEZ_Components.Led_Button(FEZ_Pin.Digital.Di4);
            FEZ_Components.Led_Button myLedButtonRight = new FEZ_Components.Led_Button(FEZ_Pin.Digital.Di2);

            FEZ_Components.Piezo myPiezo = new FEZ_Components.Piezo(FEZ_Pin.Digital.An0);

            while (true)
            {
                if (myReflectiveSensorLeft.GetState() != FEZ_Components.ReflectiveSensor.DetectingState.ReflectionDeteced) // black detected
                    myLedButtonLeft.SetState(FEZ_Components.Led_Button.LedState.TurnOn); 
                else
                    myLedButtonLeft.SetState(FEZ_Components.Led_Button.LedState.ShutOff); 

                if (myReflectiveSensorRight.GetState() != FEZ_Components.ReflectiveSensor.DetectingState.ReflectionDeteced) // black detected
                   myLedButtonRight.SetState(FEZ_Components.Led_Button.LedState.TurnOn); 
                else
                    myLedButtonRight.SetState(FEZ_Components.Led_Button.LedState.ShutOff);

                if (myLedButtonLeft.GetState() == FEZ_Components.Led_Button.ButtonState.Pressed)
                    myPiezo.Beep(8000, 100);

                if (myLedButtonRight.GetState() == FEZ_Components.Led_Button.ButtonState.Pressed)
                    myPiezo.Beep(7500, 100);

                Thread.Sleep(100);
            }
        }
    }
}

LED-button class


/*
Copyright 2010 GHI Electronics LLC
Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 
*/

using System;
using Microsoft.SPOT;
using Microsoft.SPOT.Hardware;
using GHIElectronics.NETMF.FEZ;

namespace GHIElectronics.NETMF.FEZ
{
    public static partial class FEZ_Components
    {
        public class Led_Button : IDisposable
        {
            TristatePort led_button;

            public Led_Button(FEZ_Pin.Digital pin)
            {
                led_button = new TristatePort((Cpu.Pin)pin, false, false, Port.ResistorMode.Disabled);
                if (led_button.Active)
                    led_button.Active = false;
            }

            public void Dispose()
            {
                led_button.Dispose();
            }

            public enum LedState : byte
            {
                TurnOn = 0,
                ShutOff = 1,
            }

            public void SetState(LedState ledstate)
            {
                if (ledstate == LedState.TurnOn)
                {
                    if (led_button.Active == false)
                        led_button.Active = true;
                }
                else if (ledstate == LedState.ShutOff)
                {
                    if (led_button.Active == true)
                        led_button.Active = false;
                }
            }

            public enum ButtonState : byte
            {
                NotPressed = 0,
                Pressed = 1,
            }

            public ButtonState GetState()
            {
                ButtonState butState;
                if (led_button.Active == true)
                {
                    led_button.Active = false;
                    butState = (led_button.Read() == false) ? ButtonState.Pressed : ButtonState.NotPressed;
                    led_button.Active = true;
                }
                else
                    butState = (led_button.Read() == false) ? ButtonState.Pressed : ButtonState.NotPressed;
                return butState;
            }
        }
    }
}