LED RingCoder Breakout

Board connections

The board has the following pins:
- GND (Connected to Ground)
- B (Connected to pin Netduino pin D1)
- A (Connected to pin Netduino pin D0)
- GRN (Connected to Netduino pin D4)
- RED (Connected to Netduino pin D3)
- SW (Connected to Netduino pin D2)
- DAT (Connected to SPI MOSI; Netduino pin D11)
- CLR (not connected)
- CLK (Connected to SPI Clock; Netduino pin D13)
- LATCH (Connected to SPI Chip Select; Netduino pin D10)
- EN (not connected)
- VCC (Connected to +5V)

How to connect

LEDRingCoderBreakout.png

Sample code in C#

public class Program
{
    // Defines the push button and LEDs in the knob
    public static AutoRepeatInputPort Button = new AutoRepeatInputPort(Pins.GPIO_PIN_D2, Port.ResistorMode.PullUp, true);
    public static OutputPort Red = new OutputPort(Pins.GPIO_PIN_D3, false);
    public static OutputPort Green = new OutputPort(Pins.GPIO_PIN_D4, true);

    // There are 16 LEDs in the circle around the knob
    public static IGPOPort[] Led = new IGPOPort[16];

    // We'll store an integer value of the knob
    public static int KnobValue = 0;

    public static void Main()
    {
        // Defines all 16 LEDs linked to two 74HC595 ICs in a chain
        Ic74hc595 IcChain = new Ic74hc595(SPI_Devices.SPI1, Pins.GPIO_PIN_D10, 2);
        Led = IcChain.Pins;

        // Defines the rotary encoder
        RotaryEncoder Knob = new RotaryEncoder(Pins.GPIO_PIN_D0, Pins.GPIO_PIN_D1);
        Knob.Rotated += new NativeEventHandler(Knob_Rotated);

        // Links the event to the button
        Button.StateChanged += new AutoRepeatEventHandler(Button_StateChanged);

        // Wait infinitely
        Thread.Sleep(Timeout.Infinite);
    }

    static void Button_StateChanged(object sender, AutoRepeatEventArgs e)
    {
        // We will only change when the button gets pressed
        if (Button.Read()) return;
        // Toggles Red
        Red.Write(!Red.Read());
        // Makes green invert Red
        Green.Write(!Red.Read());
    }

    /// <summary>
    /// The value has been changed
    /// </summary>
    /// <param name="Unused">Not used</param>
    /// <param name="Value">The new value</param>
    /// <param name="Time">Time of the event</param>
    static void Knob_Rotated(uint Unused, uint Value, DateTime Time)
    {
        // Increase or decrease?
        if (Value == 1)
            ++KnobValue;
        else
            --KnobValue;

        // Makes it actually go round ;-)
        if (KnobValue < 0) KnobValue = 15;
        if (KnobValue > 15) KnobValue = 0;

        // Now we'll fill up led 0 to KnobValue to display the actual value
        for (int LedNo = 0; LedNo < Led.Length; ++LedNo)
        {
            Led[LedNo].Write(KnobValue >= LedNo);
        }
    }
}

Sample code in VB

Module Module1

    ' Defines the push button and LEDs in the knob
    Dim WithEvents Button As AutoRepeatInputPort = New AutoRepeatInputPort(Pins.GPIO_PIN_D2, Port.ResistorMode.PullUp, True)
    Dim Red As OutputPort = New OutputPort(Pins.GPIO_PIN_D3, False)
    Dim Green As OutputPort = New OutputPort(Pins.GPIO_PIN_D4, True)

    'There are 16 LEDs in the circle around the knob
    Dim Led(0 To 15) As IGPOPort

    ' We'll store an integer value of the knob
    Dim KnobValue As Integer = 0

    ' Defines the rotary encoder
    Dim WithEvents Knob As RotaryEncoder = New RotaryEncoder(Pins.GPIO_PIN_D0, Pins.GPIO_PIN_D1)

    Sub Main()
        ' Defines all 16 LEDs linked to two 74HC595 ICs in a chain
        Dim IcChain As Ic74hc595 = New Ic74hc595(SPI_Devices.SPI1, Pins.GPIO_PIN_D10, 2)
        Led = IcChain.Pins

        ' Wait infinitely
        Thread.Sleep(Timeout.Infinite)
    End Sub

    Private Sub Button_StateChanged(sender As Object, e As Toolbox.NETMF.Hardware.AutoRepeatEventArgs) Handles Button.StateChanged
        ' We will only change when the button gets pressed
        If Button.Read() Then Exit Sub
        ' Toggles Red
        Red.Write(Not Red.Read())
        ' Makes green invert Red
        Green.Write(Not Red.Read())
    End Sub

    Private Sub Knob_Rotated(Unused As UInteger, Value As UInteger, time As Date) Handles Knob.Rotated
        ' Increase or decrease?
        If Value = 1 Then KnobValue = KnobValue + 1 Else KnobValue = KnobValue - 1

        ' Makes it actually go round ;-)
        If Value < 0 Then Value = 15
        If Value > 15 Then Value = 0

        ' Now we'll fill up led 0 to KnobValue to display the actual value
        For LedNo As Integer = 0 To Led.Length - 1
            If KnobValue >= LedNo Then Led(LedNo).Write(True) Else Led(LedNo).Write(False)
        Next
    End Sub
End Module

Last edited Dec 29, 2012 at 6:42 AM by Garrcomm, version 2