forked from nanoframework/nanoFramework.IoT.Device
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Mcp3201.cs
29 lines (26 loc) · 1 KB
/
Mcp3201.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
using System.Device.Spi;
namespace Iot.Device.Adc
{
/// <summary>
/// MCP32001 Analog to Digital Converter (ADC)
/// </summary>
public class Mcp3201 : Mcp3Base
{
/// <summary>
/// Constructs Mcp3201 instance
/// </summary>
/// <param name="spiDevice">Device used for SPI communication</param>
public Mcp3201(SpiDevice spiDevice)
: base(spiDevice)
{
}
/// <summary>
/// Reads a 12-bit (0..4096) value from the device
/// </summary>
/// <returns>12-bit value corresponding to relative voltage level on specified device channel</returns>
// Read the data from the device. As the 12 bits of data start at bit 1 then read 13 bits and shift right by 1.
public int Read() => ReadInternal(adcRequest: 0, adcResolutionBits: 12 + 1, delayBits: 0) >> 1;
}
}