To use the node in your project you should have the bradzilla84/touch-adafruit library installed. Use the “File → Add Library” menu item in XOD IDE if you don’t have it yet. See Using libraries for more info.
C++ implementation
// Tell XOD where it could download the library:
#pragma XOD require "https://github.com/adafruit/Adafruit_TouchScreen"
{{#global}}
#include <stdint.h>
#include "TouchScreen.h"
{{/global}}
struct State {
uint8_t mem[sizeof(TouchScreen)];
};
{{ GENERATED_CODE }}
using Type = TouchScreen*;
Type ts = new TouchScreen(9, A2, A3, 8, 300); //TouchScreen(XP, YP, XM, YM, 300)
TSPoint tp;
void evaluate(Context ctx) {
if (!isInputDirty<input_INIT>(ctx)){
return;}
auto XP = getValue<input_XP>(ctx);
auto YP = getValue<input_YP>(ctx);
auto XM = getValue<input_XM>(ctx);
auto YM = getValue<input_YM>(ctx);
auto RES = getValue<input_RES>(ctx);
if (isSettingUp()){
auto state = getState(ctx);
Type ts = new (state->mem) TouchScreen(XP, YP, XM, YM, RES);}
tp = ts->getPoint();
pinMode(A2, OUTPUT);//XM
pinMode(A3, OUTPUT);//YP
emitValue<output_XTouch>(ctx, tp.x);
emitValue<output_YTouch>(ctx, tp.y);
emitValue<output_TouchPressure>(ctx, tp.z);
if (tp.z){
emitValue<output_Touch>(ctx, 1);
}
}