示例#1
0
        public void FivePinLayout()
        {
            var pins  = new int[] { 1, 2, 3, 4, 5 };
            var nodes = CharlieplexSegment.GetNodes(pins);

            Assert.True(true);
            Assert.True(nodes.Length == 20);
            Assert.True(nodes[0].Anode == 1 && nodes[0].Cathode == 2);
            Assert.True(nodes[1].Anode == 2 && nodes[1].Cathode == 1);
            Assert.True(nodes[2].Anode == 2 && nodes[2].Cathode == 3);
            Assert.True(nodes[3].Anode == 3 && nodes[3].Cathode == 2);
            Assert.True(nodes[4].Anode == 3 && nodes[4].Cathode == 4);
            Assert.True(nodes[5].Anode == 4 && nodes[5].Cathode == 3);
            Assert.True(nodes[6].Anode == 4 && nodes[6].Cathode == 5);
            Assert.True(nodes[7].Anode == 5 && nodes[7].Cathode == 4);
            Assert.True(nodes[8].Anode == 1 && nodes[8].Cathode == 3);
            Assert.True(nodes[9].Anode == 3 && nodes[9].Cathode == 1);
            Assert.True(nodes[10].Anode == 2 && nodes[10].Cathode == 4);
            Assert.True(nodes[11].Anode == 4 && nodes[11].Cathode == 2);
            Assert.True(nodes[12].Anode == 3 && nodes[12].Cathode == 5);
            Assert.True(nodes[13].Anode == 5 && nodes[13].Cathode == 3);
            Assert.True(nodes[14].Anode == 1 && nodes[14].Cathode == 4);
            Assert.True(nodes[15].Anode == 4 && nodes[15].Cathode == 1);
            Assert.True(nodes[16].Anode == 2 && nodes[16].Cathode == 5);
            Assert.True(nodes[17].Anode == 5 && nodes[17].Cathode == 2);
            Assert.True(nodes[18].Anode == 1 && nodes[18].Cathode == 5);
            Assert.True(nodes[19].Anode == 5 && nodes[19].Cathode == 1);
        }
示例#2
0
        public void TwoPinLayout()
        {
            var pins = new int[] { 1, 2 };

            CharlieplexSegmentNode[] nodes = CharlieplexSegment.GetNodes(pins);
            Assert.True(nodes.Length == 2);
            Assert.True(nodes[0].Anode == 1 && nodes[0].Cathode == 2);
            Assert.True(nodes[1].Anode == 2 && nodes[1].Cathode == 1);
        }
示例#3
0
        public void ThreePinLayout()
        {
            var pins = new int[] { 1, 2, 3 };

            CharlieplexSegmentNode[] nodes = CharlieplexSegment.GetNodes(pins);
            Assert.True(nodes.Length == 6);
            Assert.True(nodes[0].Anode == 1 && nodes[0].Cathode == 2);
            Assert.True(nodes[1].Anode == 2 && nodes[1].Cathode == 1);
            Assert.True(nodes[2].Anode == 2 && nodes[2].Cathode == 3);
            Assert.True(nodes[3].Anode == 3 && nodes[3].Cathode == 2);
            Assert.True(nodes[4].Anode == 1 && nodes[4].Cathode == 3);
            Assert.True(nodes[5].Anode == 3 && nodes[5].Cathode == 1);
        }
示例#4
0
        public void FourPinLayoutLimitEight()
        {
            var pins = new int[] { 1, 2, 3, 4 };

            CharlieplexSegmentNode[] nodes = CharlieplexSegment.GetNodes(pins, 8);
            Assert.True(true);
            Assert.True(nodes.Length == 8);
            Assert.True(nodes[0].Anode == 1 && nodes[0].Cathode == 2);
            Assert.True(nodes[1].Anode == 2 && nodes[1].Cathode == 1);
            Assert.True(nodes[2].Anode == 2 && nodes[2].Cathode == 3);
            Assert.True(nodes[3].Anode == 3 && nodes[3].Cathode == 2);
            Assert.True(nodes[4].Anode == 3 && nodes[4].Cathode == 4);
            Assert.True(nodes[5].Anode == 4 && nodes[5].Cathode == 3);
            Assert.True(nodes[6].Anode == 1 && nodes[6].Cathode == 3);
            Assert.True(nodes[7].Anode == 3 && nodes[7].Cathode == 1);
        }
示例#5
0
文件: Program.cs 项目: qwdingyu/iot-1
        /// <summary>
        /// Application entrypoint
        /// </summary>
        public static void Main(string[] args)
        {
            var pins = new int[] { 6, 13, 19 };
            var charlieSegmentLength = 6;
            // calling this method helps with determing the correct pin circuit to use
            var nodes = CharlieplexSegment.GetNodes(pins, charlieSegmentLength);

            for (int i = 0; i < charlieSegmentLength; i++)
            {
                var node = nodes[i];
                Console.WriteLine($"Node {i} -- Anode: {node.Anode}; Cathode: {node.Cathode}");
            }

            var charlie    = new CharlieplexSegment(pins, charlieSegmentLength);
            var twoSeconds = TimeSpan.FromSeconds(2);

            Console.WriteLine("Light all LEDs");
            for (int i = 0; i < charlieSegmentLength; i++)
            {
                charlie.Write(i, 1);
            }

            charlie.DisplaySegment(twoSeconds);

            Console.WriteLine("Hit enter to continue.");
            Console.ReadLine();

            Console.WriteLine("Dim all LEDs");
            for (int i = 0; i < charlieSegmentLength; i++)
            {
                charlie.Write(i, 0);
            }

            Console.WriteLine("Write data -- light odd values -- and then display.");
            for (int i = 0; i < charlieSegmentLength; i++)
            {
                if (i % 2 == 1)
                {
                    charlie.Write(i, 1);
                }
            }

            charlie.DisplaySegment(twoSeconds);
            Thread.Sleep(1000);
            charlie.DisplaySegment(twoSeconds);

            for (int i = 0; i < charlieSegmentLength; i++)
            {
                charlie.Write(i, 0, 0);
            }

            var delayLengths = new int[] { 1, 5, 10, 25, 50, 100, 250, 500, 1000 };

            foreach (var delay in delayLengths)
            {
                Console.WriteLine($"Light one LED at a time -- Delay {delay}");
                for (int i = 0; i < charlieSegmentLength; i++)
                {
                    charlie.Write(i, 1, delay);
                    charlie.Write(i, 0, delay / 2);
                }
            }

            foreach (var delay in delayLengths.Reverse())
            {
                Console.WriteLine($"Light and then dim all LEDs, in sequence. Delay: {delay}");
                for (int i = 0; i < charlieSegmentLength; i++)
                {
                    Console.WriteLine($"light pin {i}");
                    charlie.Write(i, 1, delay);
                }

                for (int i = 0; i < charlieSegmentLength; i++)
                {
                    Console.WriteLine($"dim pin {i}");
                    charlie.Write(i, 0, delay / 2);
                }
            }
        }