To use the node in your project you should have the bradzilla84/arduino-tft-lib 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
#pragma XOD require "https://github.com/arduino-libraries/TFT"
// Include C++ library:
{{#global}}
#include <TFT.h> // Arduino TFT LCD library
#include <SPI.h>
{{/global}}
// Class wants to know ports in the moment of instantiation
// but we don't know them at this moment.
// Therefore, we reserve memory to store an instance of the class,
// and create the instance later:
struct State {
uint8_t mem[sizeof(TFT)];
};
// Define our custom type as a pointer on the class instance.
using Type = TFT*;
{{ GENERATED_CODE }}
void evaluate(Context ctx) {
// It should be evaluated only once on the first (setup) transaction
if (!isSettingUp())
return;
auto state = getState(ctx);
auto pin_cs = getValue<input_pin_cs>(ctx);
auto pin_dc = getValue<input_pin_dc>(ctx);
auto pin_reset = getValue<input_pin_reset>(ctx);
// Create a new object in the memory area reserved previously.
Type Display = new (state->mem) TFT(pin_cs, pin_dc, pin_reset);
Display->begin();
emitValue<output_DEV>(ctx, Display);
}