/// <summary> /// Reads the specified channel. /// </summary> /// <param name="channel">The channel.</param> /// <returns>The value</returns> public AnalogValue Read(Mcp3208Channel channel) { using (spiConnection.SelectSlave()) { // Start bit spiConnection.Write(true); // Channel is single-ended spiConnection.Write(true); spiConnection.Write((byte)channel, 3); // Let one clock to sample spiConnection.Synchronize(); // Read 12 bits var data = (int)spiConnection.Read(12); return(new AnalogValue(data, 0xFFF)); } }
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); } }