Touch sensor example for NXP Rapid IoT prototyping kit. Read more at https://www.hackster.io/marcomerli/riotwear-mbed-2b2011.

Dependencies:   lib_sx9500

main.cpp

Committer:
batman52
Date:
2019-12-19
Revision:
81:7a20aa99834e
Parent:
80:0f41eaa54a9b
Child:
82:a325ac3c1b73

File content as of revision 81:7a20aa99834e:

#include "mbed.h"
#include "sx9500.h"

I2C i2c0(I2C_SDA , I2C_SCL );    // I2C_SCL = PTC10,  I2C_SDA = PTC11,
SX9500 touch(i2c0, PTA24, PTA9); // TOUCH_TXEN = PTA24, TOUCH_INT = PTA9
DigitalOut touch_rst(PTA2,1);    // TOUCH_RST = PTA2

void print_state(SX9500_TouchState_t ts)
{
            if(ts.downPressed)            
                    printf("DOWN\r\n");
            if(ts.rightPressed)
                    printf("RIGHT\r\n");
            if(ts.upPressed)
                    printf("UP\r\n");
            if(ts.leftPressed)
                    printf("LEFT\r\n");            
            if(!ts.downPressed && !ts.rightPressed && !ts.upPressed && !ts.leftPressed )
                    printf("NONE\r\n"); 
}

// main() runs in its own thread in the OS
int main() {    
    SX9500_TouchState_t ts;
  
    wait(1);
  
    touch.reset();        
    wait(0.3); // wait until the reset has finished
    touch.init();
    wait(0.3);
    touch.set_active(true);    
    wait(0.3);
    
    while (true) {      

            wait(0.3);
            ts = touch.read_proximity_sensors();                 
            print_state(ts);
            
    }
}