Esempio n. 1
0
        static void Main()
        {
            const ConnectorPin dacClock = ConnectorPin.P1Pin11;
            const ConnectorPin dacCs    = ConnectorPin.P1Pin13;
            const ConnectorPin dacMosi  = ConnectorPin.P1Pin15;

            Console.WriteLine("MCP-4822 Sample: Write a changing value on Channel A");
            Console.WriteLine();
            Console.WriteLine("\tClock: {0}", dacClock);
            Console.WriteLine("\tCS: {0}", dacCs);
            Console.WriteLine("\tMOSI: {0}", dacMosi);
            Console.WriteLine();

            using (var dacConnection = new Mcp4822SpiConnection(dacClock.ToProcessor(), dacCs.ToProcessor(), dacMosi.ToProcessor(), 1))
            {
                const decimal minimum = 0.0001m;
                var           ticks   = minimum;
                var           up      = true;

                while (!Console.KeyAvailable)
                {
                    dacConnection.Write(Mcp4822Channel.ChannelA, ticks);

                    if (up)
                    {
                        ticks *= 2;
                        if (ticks >= 1)
                        {
                            up = false;
                        }
                    }
                    else
                    {
                        ticks /= 2;
                        if (ticks <= minimum)
                        {
                            up = true;
                        }
                    }

                    Thread.Sleep(100);
                }
            }
        }
Esempio n. 2
0
        static void Main(string[] args)
        {
            var dacClock = ConnectorPin.P1Pin11.ToProcessor();
            var dacCs    = ConnectorPin.P1Pin13.ToProcessor();
            var dacMosi  = ConnectorPin.P1Pin15.ToProcessor();

            using (var dacConnection = new Mcp4822SpiConnection(dacClock, dacCs, dacMosi, 1))
            {
                Console.WriteLine("MC4822 Sample: Write a changing value on Channel A");

                const decimal minimum = 0.0001m;
                var           ticks   = minimum;
                var           up      = true;

                while (!Console.KeyAvailable)
                {
                    dacConnection.Write(Mcp4822Channel.ChannelA, ticks);

                    if (up)
                    {
                        ticks *= 2;
                        if (ticks >= 1)
                        {
                            up = false;
                        }
                    }
                    else
                    {
                        ticks /= 2;
                        if (ticks <= minimum)
                        {
                            up = true;
                        }
                    }

                    Thread.Sleep(100);
                }
            }
        }
Esempio n. 3
0
 /// <summary>
 /// Writes the specified value to the pin.
 /// </summary>
 /// <param name="value">The value.</param>
 public void Write(AnalogValue value)
 {
     connection.Write(channel, value);
 }