Skip to main content

Triggers

The following functions are available for the two Trigger lines. The "X" in a function name must be replaced by the trigger number (1 or 2):

triggerMode

void triggerMode(uint8_t pin, uint8_t mode);

This function configures the input or output characteristics of a trigger pin. By default, all triggers are inputs. The function takes the following arguments:

  • pin Pin should be an integer between 1 and 2, corresponding to trigger 1 and trigger 2
  • mode sets the input or output mode. Valid options are:
    • OUTPUT: Standard output pin (3.3V CMOS push-pull)
    • OUTPUT_OPENDRAIN: Open drain output
    • INPUT: Standard input (floating)
    • INPUT_PULLUP: Input with 22k pull up resistor
    • INPUT_PULLDOWN: Input with 100k pull down resistor

Example

triggerMode(1,INPUT);
triggerMode(2,OUTPUT);

triggerWrite

void triggerWrite(uint8_t pin, uint8_t value);

This function sets a trigger output HIGH or LOW. The function takes the following arguments:

  • pin Should be an integer between 1 and 2, corresponding to trigger 1 and trigger 2.
  • value set the pin to a 0 or 1. Valid options are:
    • LOW
    • HIGH

Example

triggerWrite(1,LOW);
triggerWrite(2,HIGH);

triggerRead

uint8_t triggerRead(uint8_t pin);

The function returns a 0 if the trigger input is low and returns 1 if the trigger is high. The function takes the following arguments:

  • pin Should be an integer between 1 and 2, corresponding to trigger 1 and trigger 2.

Example

if triggerRead(1) {
//trigger1 is high
...
} else {
//trigger 1 is low
...
}

enableInterruptTrigger

void enableInterruptTrigger(uint8_t pin, trigger_edge_t edge, void (*cb_function)(void) );
void enableInterruptTrigger(uint8_t pin, trigger_edge_t edge, void (*cb_function)(void), uint priority );

This function configures the trigger to call a function on the rising, or falling, or either edge of the trigger line. The function takes the following arguments:

  • pin Should be an integer between 1 and 2, corresponding to trigger 1 and trigger 2.
  • edge Sets the edge sensitivtity of the trigger line. Valid options are:
    • FAILLING_EDGE
    • RISING_EDGE
    • BOTH_EDGES
  • cb_function Callback function to run on the rising (or falling) edge of the trigger
  • priority Optional argument to set interrupt priority. Default is 4 for trigger 1 and 5 for trigger 2. Under most circumstance, this arguments should be skipped.

Example

void setup() {  
enableInterruptTrigger(1,RISING_DGE, gotTrigger);
}

void gotTrigger(void) {}
...
}

disableInterruptTrigger

void disableInterruptTriggerX(uint8_t pin);

This function disables the trigger's interrupt function. The function takes the following arguments:

  • pin Should be an integer between 1 and 2, corresponding to trigger 1 and trigger 2.

Example

void watchTrigger(bool on) {
if (on == true) {
enableInterruptTrigger(1,RISING_EDGE, gotTrigger);
//call gotTrigger when Trigger 1 goes high
} else {
disableInterruptTrigger(1); //turn off calling gotTrigger
}
}

void gotTrigger(void) {
...
}