The Dash provides more features than a regular Arduino board. To give you easy access to Dash-specific features, we have provided a Dash class. We’ll be posting some in-depth tutorials on using these features, but here is a quick overview of what is available.
Initializing
To get the Dash class started, in your setup()
function, call
Dash.begin();
Controlling the LED
The basics:
Dash.setLED(on); //turn on if on is true, off if false
Dash.onLED(); //turn on the LED
Dash.offLED(); //turn off the LED
Dash.toggleLED(); //off->on or on->off
To blink the LED:
Dash.pulseLED(on_time, off_time);
The LED will turn on for on_time
milliseconds, turn off for off_time
milliseconds, then repeat. Stop the blink by calling one of the other LED functions.
Battery
You can get state of the battery using:
Dash.batteryPercentage();
Dash.batteryMillivolts();
These functions will only give you valid battery values if your board is configured for battery operation via the jumper settings.
Sleep
Dash.snooze(milliseconds);
Dash.sleep();
Dash.deepSleep();
Dash.shutdown();
You can use snooze()
as a lower-power replacement for the Arduino delay()
function. The sleep()
function will stay in sleep until an interrupt occurs (such as a configured IO interrupt or a serial character received). The deepSleep()
function saves more power, but can only wake up using specially configured IO interrupts (see the WKUP column in the Operation Manual). The shutdown()
function works the same as the deepSleep()
function, except that on wake up the processor resets and your program will start in the setup()
function again. The upcoming sleep tutorial will have more details.
IO Interrupts
As of version 0.7.2 for Arduino, the IO interrupt functionality has been changed to use the attachInterrupt() function. This should provide better compatibility with other Arduino sketches and libraries.
OBSOLETE
To setup IO interrupts, create a callback function in your Arduino sketch that will be called when an IO interrupt occurs. It can have any name, but it needs to returnvoid
and take a singleuint32_t
parameter.
void handle_interrupts(uint32_t io) { if(IO_MATCH(io, D01)) { //Do something because D01 changed } }
In your
setup()
function, set this function as your callback:
Dash.setIoCallback(handle_interrupts);
Now enable any IO interrupts you want to use.
Dash.enableIoInterrupt(D01, IO_INT_FALLING); //interrupt on falling edge (HIGH to LOW) of pin R03 Dash.enableIoInterrupt(D02, IO_INT_RISING); //interrupt on rising edge (LOW to HIGH) of pin R04 Dash.enableIoInterrupt(D03, IO_INT_RISING | IO_INT_FALLING); //interrupt on any change to pin R05 Dash.disableIoInterrupt(D01); //turn off the interrupt
The upcoming IO interrupts tutorial will have more details.