Пример #1
0
        /// <summary>
        /// Reads the specified channel.
        /// </summary>
        /// <param name="channel">The channel.</param>
        /// <returns>The value</returns>
        public AnalogValue Read(Mcp3008Channel channel)
        {
            using (spiConnection.SelectSlave())
            {
                // Start bit
                spiConnection.Write(true);

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

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

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

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

                return(new AnalogValue(data, 0x3FF));
            }
        }
Пример #2
0
        public decimal Read(Mcp3008Channel channel)
        {
            using (spiConnection.SelectSlave())
            {
                // Start bit
                spiConnection.Write(true);

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

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

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

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

                return(data * scale / 1024m);
            }
        }
        /// <summary>
        /// Reads the specified channel.
        /// </summary>
        /// <param name="channel">The channel.</param>
        /// <returns>The value</returns>
        public AnalogValue Read(Mcp3008Channel channel)
        {
            using(spiConnection.SelectSlave())
            {
                // Start bit
                spiConnection.Write(true);

                // Channel is single-ended
                spiConnection.Write(true);
                
                // Channel Id
                spiConnection.Write((byte)channel, 3);
                
                // Let one clock to sample
                spiConnection.Synchronize();

                // Read 10 bits
                var data = (int)spiConnection.Read(10);
                
                return new AnalogValue(data, 0x3FF);
            }
        }
        public decimal Read(Mcp3008Channel channel)
        {
            using(spiConnection.SelectSlave())
            {
                // Start bit
                spiConnection.Write(true);

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

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

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

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

                return data*scale/1024m;
            }
        }
 /// <summary>
 /// Initializes a new instance of the <see cref="Mcp3008InputAnalogPin" /> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="channel">The channel.</param>
 public Mcp3008InputAnalogPin(Mcp3008SpiConnection connection, Mcp3008Channel 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 Mcp3008InputAnalogPin In(this Mcp3008SpiConnection connection, Mcp3008Channel channel)
 {
     return new Mcp3008InputAnalogPin(connection, channel);
 }
Пример #7
0
 /// <summary>
 /// Initializes a new instance of the <see cref="Mcp3008InputAnalogPin" /> class.
 /// </summary>
 /// <param name="connection">The connection.</param>
 /// <param name="channel">The channel.</param>
 public Mcp3008InputAnalogPin(Mcp3008Device connection, Mcp3008Channel channel)
 {
     this.connection = connection;
     this.channel    = channel;
 }
Пример #8
0
 /// <summary>
 /// Gets the value from the specified channel in volts regarding to the reference value.
 /// </summary>
 public double ReadChannelInVolt(Mcp3008Channel channel, double referenceVoltage = 3.3)
 {
     var value = ReadChannel(channel);
     return ChannelValueToVolt(value, referenceVoltage);
 }
Пример #9
0
 /// <summary>
 /// Gets the current value from one of the channels (0 - 1024).
 /// </summary>
 public double ReadChannel(Mcp3008Channel channel)
 {
     return Convert.ToDouble(_adcConnection.In(channel).Read().Value);
 }
Пример #10
0
 /// <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 Mcp3008InputAnalogPin In(this Mcp3008Device connection, Mcp3008Channel channel)
 {
     return(new Mcp3008InputAnalogPin(connection, channel));
 }
Пример #11
0
        /// <summary>
        /// Gets the value from the specified channel in volts regarding to the reference value.
        /// </summary>
        public double ReadChannelInVolt(Mcp3008Channel channel, double referenceVoltage = 3.3)
        {
            var value = ReadChannel(channel);

            return(ChannelValueToVolt(value, referenceVoltage));
        }
Пример #12
0
 /// <summary>
 /// Gets the current value from one of the channels (0 - 1024).
 /// </summary>
 public double ReadChannel(Mcp3008Channel channel)
 {
     return(Convert.ToDouble(_adcConnection.In(channel).Read().Value));
 }
Пример #13
0
 public IInputAnalogPin GetChannel(Mcp3008Channel ch)
 {
     return(spiConnection.In(ch));
 }