# How to use analog output

The melonbotics Encoder offers analog absolute output on the 3-Pin JST port.

## Specs

* Maximum angle error of ±1.0° (Integral Non-Linearity)
* 12-Bit DAC
* 5us Propagation Delay
* Output Range 0V -> 3.2V (when used on at 3.3V)

## Wiring

#### Method 1 (Recommended)

Use the [JST Joiner Board](https://www.melonbotics.com/products/jst-joiner-board) to connect two Encoders to one Control Hub analog port.&#x20;

<figure><img src="https://1580331926-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnHZmDkFp5cOUYczo9V98%2Fuploads%2FHpyR2JcRnBhjJflT1472%2FIMG-8611.jpg?alt=media&#x26;token=dd896b0e-8c29-4aa7-a64d-8801d47a4060" alt="" width="188"><figcaption></figcaption></figure>

#### Method 2 **(Not Recommended)**

Splice the included 3-Pin cable, with the included 4-Pin cable to create an adapter. See below diagram for connector pinouts.

<figure><img src="https://1580331926-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2FnHZmDkFp5cOUYczo9V98%2Fuploads%2F5n37A6dkb10egNK6CbSK%2FEncoder%20pinout.png?alt=media&#x26;token=28c0ec81-d094-4559-864c-2567eda3c5e3" alt="" width="375"><figcaption></figcaption></figure>

## Code Example

```java
// Get analog port instance from hardwareMap
AnalogInput encoder = hardwareMap.get(AnalogInput.class, "encoder");

// Simple position return
double position = encoder.getVoltage() / 3.2 * 360;

// Position return with adjustable offset
// Offset must be positive, otherwise the modulo (%) operation breaks
//
// If you want to use a negative offset, just add some multiple of 360 so
// that the offset evaluates to be positive.
double offset = -123.4 + 360;
double offsetPosition = (encoder.getVoltage() / 3.2 * 360 + offset) % 360;
```
