Main Site Documentation

TinyCLR and 7 Segment


#1

Just tried TinyCLR Os and 7 Segment and love it!

using GHIElectronics.TinyCLR.Devices.Gpio;
using System;
using System.Collections;
using System.Text;
using System.Threading;

namespace _7SegmentLeds
{
    class LDS5463EX
    {        
        const int DIG1_PIN_ID = 11;
        const int DIG2_PIN_ID = 8;
        const int DIG3_PIN_ID = 7;
        const int DIG4_PIN_ID = 5;

        const int SEGA_PIN_ID = 10;
        const int SEGB_PIN_ID = 6;
        const int SEGC_PIN_ID = 3;
        const int SEGD_PIN_ID = 1;
        const int SEGE_PIN_ID = 0;
        const int SEGF_PIN_ID = 9;
        const int SEGG_PIN_ID = 4;
        const int SEGDP_PIN_ID = 2;

        const bool ON = true;
        const bool OFF = false;

        private GpioPin[] digPins;
        private GpioPin[] segPins;

        static byte[] FontNumber = { 0b00111111, 0b00000110, 0b01011011, 0b01001111, 0b01100110, 0b01101101, 0b01111101, 0b00000111, 0b01111111, 0b01101111 };

        public LDS5463EX(int[] pins) {

            digPins = GpioController.GetDefault().OpenPins(new int[] { pins[DIG1_PIN_ID], pins[DIG2_PIN_ID], pins[DIG3_PIN_ID], pins[DIG4_PIN_ID] });
            segPins = GpioController.GetDefault().OpenPins(new int[] { pins[SEGA_PIN_ID], pins[SEGB_PIN_ID], pins[SEGC_PIN_ID], pins[SEGD_PIN_ID],
                                                                       pins[SEGE_PIN_ID], pins[SEGF_PIN_ID], pins[SEGG_PIN_ID], pins[SEGDP_PIN_ID] });

            for (var i = 0; i < digPins.Length; i++)
            {
                digPins[i].SetDriveMode(GpioPinDriveMode.Output);
                digPins[i].Write(GpioPinValue.High);
            }

            for (var i = 0; i < segPins.Length; i++)
            {
                segPins[i].SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
        }

        private void SetSegment(int pos, bool on)
        {
            if (on)
            {
                segPins[pos].SetDriveMode(GpioPinDriveMode.Output);
                segPins[pos].Write(GpioPinValue.Low);
            }
            else
            {
                segPins[pos].SetDriveMode(GpioPinDriveMode.InputPullUp);
            }
        }

        private void SetDig(int pos, bool on)
        {
            digPins[pos].Write(on ? GpioPinValue.High : GpioPinValue.Low);
        }

        public void Clear()
        {
            for (var i = 0; i < 4; i++)
            {
                SetDig(i, OFF);
            }

            for (var i = 0; i < 8; i++)
            {
                SetSegment(i, OFF);
            }
        }

        public void DrawDp(bool on)
        {
            for (var i = 0; i < 8; i++)
            {
                SetSegment(i, on ? i == 7 ? ON : OFF : OFF);
            }

            for (var i = 0; i < 4; i++)
            {
                SetDig(i, on ? i == 1 ? ON : OFF : OFF);
            }
        }  
        
        public void DrawNumber(int pos, int number)
        {
            for (var i = 0; i < 4; i++)
            {
                var value = (pos == i) ? ON : OFF;
                SetDig(i, value);
            }

            for (var i = 0; i < 8; i++)
            {
                var value = (FontNumber[number] & (1 << i)) != 0 ? ON : OFF;
                SetSegment(i, value);
            }
        }
    }
}


#2

Is it a click module or you made this board?


#3

Soldering by hand.