markneustadt.com

Netduino Chasing Seven Segment Display

In this example, I have hooked the Netduino board to a seven segment display along with a potentiometer.


Download the Fritzing Chasing 7 Segment.fzz schematic

Chasing 7 Segment

 

When the unit is programmed and powered up, the segements will chase around. The potentiometer is used to control how fast the segments chase.

Download SegmentedDisplay project file

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 SegmentedDisplay
{
    public class Program
    {
        #region Boilerplate Pinout Declarations

        static OutputPort d0 = new OutputPort(Pins.GPIO_PIN_D0, false);
        static OutputPort d1 = new OutputPort(Pins.GPIO_PIN_D1, false);
        static OutputPort d2 = new OutputPort(Pins.GPIO_PIN_D2, false);
        static OutputPort d3 = new OutputPort(Pins.GPIO_PIN_D3, false);
        static OutputPort d4 = new OutputPort(Pins.GPIO_PIN_D4, false);
        static OutputPort d5 = new OutputPort(Pins.GPIO_PIN_D5, false);
        static OutputPort d6 = new OutputPort(Pins.GPIO_PIN_D6, false);
        static OutputPort d7 = new OutputPort(Pins.GPIO_PIN_D7, false);
        static OutputPort d8 = new OutputPort(Pins.GPIO_PIN_D8, false);
        static OutputPort d9 = new OutputPort(Pins.GPIO_PIN_D9, false);
        static OutputPort d10 = new OutputPort(Pins.GPIO_PIN_D10, false);
        static OutputPort d11 = new OutputPort(Pins.GPIO_PIN_D11, false);

        #endregion

        // value to hold the delay
        static int readValue;

        // analog input for the potentiometer
        static SecretLabs.NETMF.Hardware.AnalogInput analogIn = new SecretLabs.NETMF.Hardware.AnalogInput(Pins.GPIO_PIN_A3);

        public static void Main()
        {
            // set the allowable value for the pot
            analogIn.SetRange(10, 500);

            // get the initial value from the pot
            readValue = analogIn.Read();

            // declare the onboard button.
            InputPort button = new InputPort(Pins.ONBOARD_BTN, false, Port.ResistorMode.Disabled);

            // loop while the button has not been pressed
            while (!button.Read())
            {
                // write the value of the pot
                Debug.Print("Pot Value = " + readValue.ToString());

                // loop the segments of the LED
                Flash0();
                Flash3();
                Flash2();
                Flash4();
                Flash6();
                Flash7();
            }

            // the user pressed the button - make sure all segments are off
            d0.Write(false);
            d1.Write(false);
            d2.Write(false);
            d3.Write(false);
            d4.Write(false);
            d5.Write(false);
            d6.Write(false);
            d7.Write(false);
        }

        /// <summary>
        /// read the pot value, turn on the segment connected to Pins.GPIO_PIN_D0, sleep for a bit and then turn the segment off
        /// </summary>
        private static void Flash0()
        {
            readValue = analogIn.Read();
            d0.Write(true);
            Thread.Sleep(readValue);
            d0.Write(false);
        }

        /// <summary>
        /// read the pot value, turn on the segment connected to Pins.GPIO_PIN_D1, sleep for a bit and then turn the segment off
        /// </summary>
        private static void Flash1()
        {
            readValue = analogIn.Read();
            d1.Write(true);
            Thread.Sleep(readValue);
            d1.Write(false);
        }

        /// <summary>
        /// read the pot value, turn on the segment connected to Pins.GPIO_PIN_D2, sleep for a bit and then turn the segment off
        /// </summary>
        private static void Flash2()
        {
            readValue = analogIn.Read();
            d2.Write(true);
            Thread.Sleep(readValue);
            d2.Write(false);
        }

        /// <summary>
        /// read the pot value, turn on the segment connected to Pins.GPIO_PIN_D3, sleep for a bit and then turn the segment off
        /// </summary>
        private static void Flash3()
        {
            readValue = analogIn.Read();
            d3.Write(true);
            Thread.Sleep(readValue);
            d3.Write(false);
        }

        /// <summary>
        /// read the pot value, turn on the segment connected to Pins.GPIO_PIN_D4, sleep for a bit and then turn the segment off
        /// </summary>
        private static void Flash4()
        {
            readValue = analogIn.Read();
            d4.Write(true);
            Thread.Sleep(readValue);
            d4.Write(false);
        }

        /// <summary>
        /// read the pot value, turn on the segment connected to Pins.GPIO_PIN_D5, sleep for a bit and then turn the segment off
        /// </summary>
        private static void Flash5()
        {
            readValue = analogIn.Read();
            d5.Write(true);
            Thread.Sleep(readValue);
            d5.Write(false);
        }

        /// <summary>
        /// read the pot value, turn on the segment connected to Pins.GPIO_PIN_D6, sleep for a bit and then turn the segment off
        /// </summary>
        private static void Flash6()
        {
            readValue = analogIn.Read();
            d6.Write(true);
            Thread.Sleep(readValue);
            d6.Write(false);
        }

        /// <summary>
        /// read the pot value, turn on the segment connected to Pins.GPIO_PIN_D7, sleep for a bit and then turn the segment off
        /// </summary>
        private static void Flash7()
        {
            readValue = analogIn.Read();
            d7.Write(true);
            Thread.Sleep(readValue);
            d7.Write(false);
        }

    }
}

ChasingSevenSegment_06 copy@1920px

ChasingSevenSegment_05 copy@1920px

ChasingSevenSegment_04 copy@1920px

ChasingSevenSegment_02 copy@1920px

ChasingSevenSegment_01 copy@1920px

ChasingSevenSegment_03 copy@1920px

Scroll To Top