Example #1
0
        /// <summary>
        /// Writes the specified data.
        /// </summary>
        /// <param name="channel">The channel.</param>
        /// <param name="data">The data.</param>
        public void Write(Mcp4822Channel channel, AnalogValue data)
        {
            using (spiConnection.SelectSlave())
            {
                var value = (uint)(data.Relative * 0xFFF);
                if (value > 0xFFF)
                {
                    value = 0xFFF;
                }

                // Set active channel
                spiConnection.Write(channel == Mcp4822Channel.ChannelB);

                // Ignored bit
                spiConnection.Synchronize();

                // Select 1x Gain
                spiConnection.Write(true);

                // Active mode operation
                spiConnection.Write(true);

                // Write 12 bits data (some lower bits are ignored by MCP4802/4812
                spiConnection.Write(value, 12);
            }
        }
        /// <summary>
        /// Writes the specified data.
        /// </summary>
        /// <param name="channel">The channel.</param>
        /// <param name="data">The data.</param>
        public void Write(Mcp4822Channel channel, AnalogValue data)
        {
            using (spiConnection.SelectSlave())
            {
                var value = (uint)(data.Relative * 0xFFF);
                if (value > 0xFFF)
                    value = 0xFFF;

                // Set active channel
                spiConnection.Write(channel == Mcp4822Channel.ChannelB);

                // Ignored bit
                spiConnection.Synchronize();

                // Select 1x Gain
                spiConnection.Write(true);

                // Active mode operation
                spiConnection.Write(true);

                // Write 12 bits data (some lower bits are ignored by MCP4802/4812
                spiConnection.Write(value, 12);
            }
        }
Example #3
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Mcp4822OutputAnalogPin" /> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="channel">The channel.</param>
 public Mcp4822OutputAnalogPin(Mcp4822SpiConnection connection, Mcp4822Channel channel)
 {
     this.connection = connection;
     this.channel    = channel;
 }
 /// <summary>
 /// Creates an output analog pin.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="channel">The channel.</param>
 /// <param name="scale">The maximum.</param>
 /// <returns>The pin.</returns>
 public static Mcp4822OutputAnalogPin Out(this Mcp4822SpiConnection connection, Mcp4822Channel channel)
 {
     return new Mcp4822OutputAnalogPin(connection, channel);
 }
 /// <summary>
 /// Creates an output analog pin.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="channel">The channel.</param>
 /// <returns>The pin.</returns>
 public static Mcp4822OutputAnalogPin Out(this Mcp4822Device connection, Mcp4822Channel channel)
 {
     return(new Mcp4822OutputAnalogPin(connection, channel));
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Mcp4822OutputAnalogPin" /> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="channel">The channel.</param>
 public Mcp4822OutputAnalogPin(Mcp4822SpiConnection connection, Mcp4822Channel channel)
 {
     this.connection = connection;
     this.channel = channel;
 }