readVoltage
Reads the input voltage from a specified analog pin.
func readVoltage() -> Float
Returns
A float value in the range of 0.0 to the reference voltage.
Reads the input voltage from a specified analog pin.
func readVoltage() -> Float
A float value in the range of 0.0 to the reference voltage.
import SwiftIO
The SwiftIO library allows you to access and control the hardware in an easy way.
final class AnalogIn
The AnalogIn class reads external voltage from an analog input pin, which functions like a multimeter for measuring input values.
@frozen struct Float
A single-precision, floating-point value type.
func read() -> Int
Reads the raw value representing the analog voltage level on the specified pin. It’s the same as readRawValue()
.
func readPercentage() -> Float
Read the percentage of current input in relation to the max value from a specified analog pin.
func readRawValue() -> Int
Reads the raw value representing the analog voltage level on the specified pin.
init(_ idName: Id)
Initializes a specified pin as AnalogIn.
var maxRawValue: Int { get }
The max raw value of the ADC. It depends on ADC resolution, i.e. 255 for an 8-bit ADC and 4095 for a 12-bit ADC.
let obj: UnsafeMutableRawPointer
var refVoltage: Float { get }
The reference voltage of the ADC.
var resolutionBits: Int { get }
The number of bits in the absolute value of the ADC. Different ADC has different resolutions. The max raw value of an 8-bit ADC is 255 and that one of a 10-bit ADC is 4095.