Skip to content

ExoSenseMKR

nemax68 edited this page Jul 18, 2019 · 19 revisions

This library provides simple functions to monitor and control Exo Sense MKR's I/Os and environment data sensors.

Import the library in your sketch:

#include <ExoSenseMKR.h>

The library includes the following constants, that corresponds to Exo Sense MKR's pins (inputs/outputs) and internal resources:

DI1     DI2     digital input

OC1             open collector output

BUZZER          internal buzzer  

SOUND           internal sound level meter

Following are the available methods:

read

ExoSenseMKR.read(uint8_t pin)

This method returns the value read from the specified pin (DI1 or DI2).

write

ExoSenseMKR.write(uint8_t pin, uint8_t value)

This method writes the passed value to the specified pin (OC1) or resource(BUZZER).

buzzer

ExoSenseMKR.buzzer(uint8_t value)

This method enable/disable directly the internal buzzer (value=0 --> buzzer silent, value=1 --> buzzer sound).

sound

ExoSenseMKR.sound(void)

This method return the sound level meter (12 bit 0-4095 value).

soundAvg

ExoSenseMKR.soundAvg(void)

This method return the average sound level meter (12 bit 0-4095 value).

readAnalogAvg

Iono.readAnalogAvg(uint8_t pin, int n)

This method returns the average of n subsequent readings on the specified analog input.

subscribeDigital

Iono.subscribeDigital(uint8_t pin, unsigned long stableTime, Callback *callback);

This method can be used to attach a callback method to the change of state of a digital input.

The callback parameter must point to a void function accepting two parameters: a uint8_t and a float; for instance:

void myCallback(uint8_t pin, float value)

This function will be called every time the specified pin changes state and maintains such state at least for a time equal to the stableTime parameter, in milliseconds. The parameters passed to the callback function will correspond to the monitored pin and the value that triggered the call.

subscribeAnalog

Iono.subscribeAnalog(uint8_t pin, unsigned long stableTime, float minVariation, Callback *callback)

This method can be used to attach a callback method to the change of state of an analog input.

The callback parameter must point to a void function accepting two parameters: a uint8_t and a float; for instance:

void myCallback(uint8_t pin, float value)

This function will be called every time the specified pin changes value of an amount equal or bigger than the minVariation parameter and maintains such difference at least for a time equal to the stableTime parameter, in milliseconds. The parameters passed to the callback function will correspond to the monitored pin and the value that triggered the call.

linkDiDo

Iono.linkDiDo(uint8_t dix, uint8_t dox, uint8_t mode, unsigned long stableTime)

This function can be used to link the state of a digital input (DI1...DI6) to a relay output (DO1...DO6).

The mode parameter can be set to:
LINK_FOLLOW: to have the relay closed when the input is high and open when low
LINK_INVERT: to have the relay open when the input is high and closed when low
LINK_FLIP_H: to have the relay flipped at any input transition from low to high
LINK_FLIP_L: to have the relay flipped at any input transition from high to low
LINK_FLIP_T: to have the relay flipped at any input transition (low to high or high to low)

The stableTime parameter specifies the minimum time (in millisecond) the input must maintain its state before the command is performed on the relay (debounce filter).

N.B. This function can be used in combination with subscribeDigital(), but the stableTime parameters must be set to the same value.

flip

Iono.flip(uint8_t pin)

This method switches the state of the specified digital output pin (i.e. DO1...DO6).

process

Iono.process()

This method must be called periodically (inside the loop() function) if subscribeDigital(), subscribeAnalog() or linkDiDo() are used.

This method checks the inputs and calls the callback functions and performs the relay actions if required.

Examples

The library folder includes some examples that can be opened directly from the Arduino IDE menu File > Examples > Iono.

  • Glow shows how to control the analog output, making the LED glow;
  • ShaveAndAHaircut shows how to play some music with Iono's relays;
  • Subscribe shows how to use the subscribe methods to monitor inputs;
  • Link shows how to use the linkDiDo function.

Clone this wiki locally