Exemplo n.º 1
0
        /// <summary>
        /// Reads the specified channel.
        /// </summary>
        /// <param name="channel">The channel.</param>
        /// <returns>The value.</returns>
        public AnalogValue Read(Mcp3002Channel channel)
        {
            using (this.spiConnection.SelectSlave())
            {
                // Start bit
                this.spiConnection.Write(true);

                // Channel is single-ended
                this.spiConnection.Write(true);

                // Channel Id
                this.spiConnection.Write((byte)channel, 1);

                // Let one clock to sample
                this.spiConnection.Synchronize();

                // Read 10 bits
                var data = (int)this.spiConnection.Read(10);

                return(new AnalogValue(data, 0x3FF));
            }
        }
        /// <summary>
        /// Reads the specified channel.
        /// </summary>
        /// <param name="channel">The channel.</param>
        /// <returns>The value</returns>
        public AnalogValue Read(Mcp3002Channel channel)
        {
            using(spiConnection.SelectSlave())
            {
                // Start bit
                spiConnection.Write(true);

                // Channel is single-ended
                spiConnection.Write(true);

                // Channel Id
                spiConnection.Write((byte)channel, 1);

                // Let one clock to sample
                spiConnection.Synchronize();

                // Read 10 bits
                var data = (int)spiConnection.Read(10);

                return new AnalogValue(data, 0x3FF);
            }
        }
 /// <summary>
 /// Creates an analog input pin.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="channel">The channel.</param>
 /// <returns>The pin.</returns>
 public static Mcp3002InputAnalogPin In(this Mcp3002SpiConnection connection, Mcp3002Channel channel)
 {
     return(new Mcp3002InputAnalogPin(connection, channel));
 }
Exemplo n.º 4
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Mcp3002InputAnalogPin" /> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="channel">The channel.</param>
 public Mcp3002InputAnalogPin(Mcp3002SpiConnection connection, Mcp3002Channel channel)
 {
     this.connection = connection;
     this.channel    = channel;
 }
 /// <summary>
 /// Creates an analog input pin.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="channel">The channel.</param>
 /// <returns>The pin.</returns>
 public static Mcp3002InputAnalogPin In(this Mcp3002SpiConnection connection, Mcp3002Channel channel)
 {
     return new Mcp3002InputAnalogPin(connection, channel);
 }
 /// <summary>
 /// Initializes a new instance of the <see cref="Mcp3002InputAnalogPin" /> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="channel">The channel.</param>
 public Mcp3002InputAnalogPin(Mcp3002SpiConnection connection, Mcp3002Channel channel)
 {
     this.connection = connection;
     this.channel = channel;
 }