HELP ME **attachInterrupt** code

I want a node for the following code, HELP ME

const byte ledPin = 13;
const byte interruptPin = 2;
volatile byte state = LOW;

void setup() {
pinMode(ledPin, OUTPUT);
pinMode(interruptPin, INPUT_PULLUP);
attachInterrupt(digitalPinToInterrupt(interruptPin), blink, CHANGE);

void loop() {
digitalWrite(ledPin, state);

void blink() {
state = !state;

Sorry. I don’t have any experience working with interrupts. I can tell you you probably want to create a node that takes 2 port #s as input, the outputs state. The actual control of the LED would be using an led node fed from the state output of the interrupt node.

I’m not sure, but I think your blink() function will need to be in the interrupt node; currently there is no way to pass functions between nodes in XOD. If I remember correctly, you can directly call IDE functions from not-implemented-in-xod C++ by using ::. For example:

::attachInterrupt(::digitalPinToInterrupt(interruptPin), blink, CHANGE);

I’m not certain this will work for you, though. See digital-write & digital-read-pullup nodes for pin initialization examples (and usage of :: to call IDE functions). It is not ideal, but text-lcd-i2c-device has an example of storing state information (I don’t think you want to use struct Type for your node and you don’t need an array as shown in this struct State example). Sorry…I’m too lazy to keep digging for a more appropriate example…

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.