{
  "patches": {
    "@/main": {
      "links": {
        "HJwa1L-lY": {
          "id": "HJwa1L-lY",
          "output": {
            "nodeId": "BkqjJ8-gF",
            "pinKey": "HyJww_ONL"
          },
          "input": {
            "nodeId": "S1HayLWeK",
            "pinKey": "HkXK-dGob"
          }
        }
      },
      "nodes": {
        "BkqjJ8-gF": {
          "id": "BkqjJ8-gF",
          "type": "@/ads1115-16bit-new",
          "position": {
            "x": 12,
            "y": 2,
            "units": "slots"
          },
          "boundLiterals": {
            "SkrrDOdNU": "Continuously"
          }
        },
        "S1HayLWeK": {
          "id": "S1HayLWeK",
          "type": "xod/debug/watch",
          "position": {
            "x": 12,
            "y": 3,
            "units": "slots"
          }
        }
      },
      "path": "@/main"
    },
    "@/ads1115-16bit-new": {
      "attachments": [
        {
          "filename": "patch.cpp",
          "encoding": "utf-8",
          "content": "#pragma XOD require \"https://github.com/adafruit/Adafruit_ADS1X15\"\n\n#pragma XOD evaluate_on_pin disable\n#pragma XOD evaluate_on_pin enable input_UPDATE\n#pragma XOD error_raise enable\n\n\n#include <Wire.h>\n#include <Adafruit_ADS1X15.h>\n\n\nnode{\n\n    meta{\n\n        using Type = Adafruit_ADS1115*;\n\n\n    }\n\n    Adafruit_ADS1115  adc = Adafruit_ADS1115();\n\nvoid evaluate(Context ctx) {\n\nif(isSettingUp()) {\n        Number address = getValue<input_ADDR>(ctx);\n        if(!adc.begin(address)){\n            raiseError(ctx);\n            return;\n        }\n    }\n    \n   if (!isInputDirty<input_UPDATE>(ctx))\n       return;\n\n\n\n    \n    auto gain = getValue<input_GAIN>(ctx);\n    if(gain==0.66){adc.setGain(GAIN_TWOTHIRDS);}    // 2/3x gain +/- 6.144V  1 bit = 0.1875mV\n    else if(gain==1){adc.setGain(GAIN_ONE);}             // 1x gain   +/- 4.096V  1 bit = 0.125mV\n    else if(gain==2){adc.setGain(GAIN_TWO);}             // 2x gain   +/- 2.048V  1 bit = 0.0625mV\n    else if(gain==4){adc.setGain(GAIN_FOUR);}            // 4x gain   +/- 1.024V  1 bit = 0.03125mV\n    else if(gain==8){adc.setGain(GAIN_EIGHT);}           // 8x gain   +/- 0.512V  1 bit = 0.015625mV\n    else if(gain==16){adc.setGain(GAIN_SIXTEEN);}        // 16x gain  +/- 0.256V  1 bit = 0.0078125mV\n\n    \n    \n    int16_t buffer;\n    buffer=adc.readADC_SingleEnded(0); emitValue<output_A0>(ctx, buffer);\n    buffer=adc.readADC_SingleEnded(1); emitValue<output_A1>(ctx, buffer);\n    buffer=adc.readADC_SingleEnded(2); emitValue<output_A2>(ctx, buffer);\n    buffer=adc.readADC_SingleEnded(3); emitValue<output_A3>(ctx, buffer);\n    buffer=adc.readADC_Differential_0_1(); emitValue<output_A0_1>(ctx, buffer);\n    buffer=adc.readADC_Differential_2_3(); emitValue<output_A2_3>(ctx, buffer);\n    emitValue<output_DONE>(ctx, 1);\n}\n\n}\n"
        }
      ],
      "nodes": {
        "B1989hdV8": {
          "description": "Spits the latest value of channel A2 - A3 (differential reading).",
          "label": "A2-3",
          "id": "B1989hdV8",
          "position": {
            "x": 13,
            "y": 3,
            "units": "slots"
          },
          "type": "xod/patch-nodes/output-number"
        },
        "B1AGvhdV8": {
          "boundLiterals": {
            "__out__": "48h"
          },
          "description": "Device adress on I2C bus.",
          "label": "ADDR",
          "id": "B1AGvhdV8",
          "position": {
            "x": 9,
            "y": 1,
            "units": "slots"
          },
          "type": "xod/patch-nodes/input-byte"
        },
        "H120huON8": {
          "description": "Spits a pulse when done reading.",
          "label": "DONE",
          "id": "H120huON8",
          "position": {
            "x": 14,
            "y": 3,
            "units": "slots"
          },
          "type": "xod/patch-nodes/output-pulse"
        },
        "HkAkmKONI": {
          "description": "Spits the latest value of channel A2",
          "label": "A2",
          "id": "HkAkmKONI",
          "position": {
            "x": 10,
            "y": 3,
            "units": "slots"
          },
          "type": "xod/patch-nodes/output-number"
        },
        "HkKvRFdVU": {
          "boundLiterals": {
            "__out__": "0.66"
          },
          "description": "Set the PGA gain",
          "label": "GAIN",
          "id": "HkKvRFdVU",
          "position": {
            "x": 11,
            "y": 1,
            "units": "slots"
          },
          "type": "xod/patch-nodes/input-number"
        },
        "Hke7Fj_EL": {
          "description": "Spits the latest value of channel A0 - A1 (differential reading).",
          "label": "A0-1",
          "id": "Hke7Fj_EL",
          "position": {
            "x": 12,
            "y": 3,
            "units": "slots"
          },
          "type": "xod/patch-nodes/output-number"
        },
        "HyJww_ONL": {
          "description": "Spits the latest value of channel A0",
          "label": "A0",
          "id": "HyJww_ONL",
          "position": {
            "x": 8,
            "y": 3,
            "units": "slots"
          },
          "type": "xod/patch-nodes/output-number"
        },
        "Hyg0yQYO4L": {
          "description": "Spits the latest value of channel A3",
          "label": "A3",
          "id": "Hyg0yQYO4L",
          "position": {
            "x": 11,
            "y": 3,
            "units": "slots"
          },
          "type": "xod/patch-nodes/output-number"
        },
        "SJQQDOuNL": {
          "description": "ADS1115 Chip",
          "id": "SJQQDOuNL",
          "position": {
            "x": 11,
            "y": 2,
            "units": "slots"
          },
          "type": "xod/patch-nodes/not-implemented-in-xod"
        },
        "SkKDvuuEU": {
          "description": "Spits the latest value of channel A1",
          "label": "A1",
          "id": "SkKDvuuEU",
          "position": {
            "x": 9,
            "y": 3,
            "units": "slots"
          },
          "type": "xod/patch-nodes/output-number"
        },
        "SkrrDOdNU": {
          "description": "Feed a pulse signal to conduct analog reading.",
          "label": "UPDATE",
          "id": "SkrrDOdNU",
          "position": {
            "x": 13,
            "y": 1,
            "units": "slots"
          },
          "type": "xod/patch-nodes/input-pulse"
        }
      },
      "path": "@/ads1115-16bit-new"
    }
  },
  "name": "adafruit-ads1115"
}
