Example 5: Tap Counter

After having learned the basics about driving an E-paper screen let’s have a look at the integrated accelerometer. One of its nice features is the supported Tap detection. This allows you to trigger an interrupt, setting a GPIO pin HIGH which can be detected by your micro controller. This setup allows you to add a cheap feedback loop to your projects by implementing a kind of single touch emulation.

Accelerometer: Tap detection

The following sketch shows you who to detect a finger tap and increase a counter based on the users input.

Demo

Demo of different update modes

Sketch

SYSTEM_MODE(SEMI_AUTOMATIC);

#define EPD_RST     A0
#define EPD_BUSY    A1
#define EPD_CS      A2
#define ACC_CS      D6

#include "Adafruit_GFX.h"
#include "PL_microEPD.h"


PL_microEPD display(EPD_CS, EPD_RST, EPD_BUSY);
BO_BMA250   accel(ACC_CS);
int         i       = 0;
bool        status  = false;     //0 = stopped, 1 = running

void setup() {
    pinMode(WKP, INPUT);

    SPI.begin();
    SPI.setBitOrder(MSBFIRST);
    SPI.setDataMode(SPI_MODE0);
    SPI.setClockDivider(SPI_CLOCK_DIV4);

    display.begin();
    display.setTextSize(6);
    display.setCursor(0,4);
    display.print(i);
    display.drawCircle(170, 36, 40, EPD_LGRAY);
    display.drawCircle(170, 36, 45, EPD_LGRAY);
    display.drawCircle(170, 36, 50, EPD_LGRAY);
    display.drawCircle(170, 36, 55, EPD_LGRAY);
    display.drawCircle(170, 36, 70, EPD_LGRAY);
    display.drawCircle(170, 36, 75, EPD_LGRAY);
    display.drawCircle(0, 36, 135, EPD_LGRAY);
    display.drawCircle(0, 36, 120, EPD_LGRAY);
    display.drawCircle(0, 36, 95, EPD_LGRAY);
    display.setTextSize(1);
    display.setCursor(0, 52);
    display.print("Please tap to increase  the counter!");
    display.update();

    accel.begin();
    accel.activateTapOnInt1();
}

void loop() {
    if (digitalRead(WKP)==HIGH) {
        status = !status;
        if (status==true) {
            i+=1;
            display.fillRect(0, 4, 70, 43, EPD_WHITE);
            display.setTextSize(6);
            display.setCursor(0,4);
            display.print(i);
            display.update(EPD_UPD_MONO);
            status = !status;
        };
        delay(1000);
    };
}

In the next example we’ll see how to use the accelerometer interrupt to wake-up a micro controller. This enables us to put the MCU in deep-sleep for most of the times which is a good approach to reduce the overall power consumption.