![](/media/cache/profiles/dream_vangogh.jpg.50x50_q85.jpg)
Touch sensor example for NXP Rapid IoT prototyping kit. Read more at https://www.hackster.io/marcomerli/riotwear-mbed-2b2011.
main.cpp
- Committer:
- batman52
- Date:
- 2019-12-02
- Revision:
- 80:0f41eaa54a9b
- Parent:
- 79:0431b9fd3dc0
- Child:
- 81:7a20aa99834e
File content as of revision 80:0f41eaa54a9b:
#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 // main() runs in its own thread in the OS int main() { touch.reset(); touch.set_active(true); wait(1); while (true) { #if(1) char CSn; for(CSn = 0; CSn < 3; CSn++) { touch.print_sensor(CSn); wait(0.25); } #else //////////////////////////////////////////////////////////////////////////////// touch.RegProxCtrl0.octet = touch.read_single(SX9500_REG_PROXCTRL0); touch.RegProxCtrl0.bits.sensor_en = 3; // CS0 and CS1 on touch.write(SX9500_REG_PROXCTRL0, touch.RegProxCtrl0.octet); touch.write(SX9500_REG_PROXCTRL6, 1); // threshold to 20 for CS1 release touch.write(SX9500_REG_IRQMSK, 0x60); // enable near and far interrupts touch.set_active(true); printf("RegProxCtrl0:%02x\r\n", touch.read_single(SX9500_REG_PROXCTRL0)); // sensor-enable and scan period wait(0.5); #endif } } /************************** sx9500... ************************************* else if (pcbuf[0] == '9' && pcbuf[1] == '5') { if (pcbuf[2] == '?') { printf("95R reset\r\n"); printf("95. read status\r\n"); printf("95t[%%d] get/set PROXTHRESH\r\n"); printf("95s[%%d] get/set SCANPERIOD\r\n"); printf("95a toggle txen\r\n"); } else if (pcbuf[2] == '.') { printf("(txen) active:%d\r\n", sx9500.get_active()); printf("RegStat:%02x\r\n", sx9500.read_single(SX9500_REG_STAT)); printf("RegProxCtrl0:%02x\r\n", sx9500.read_single(SX9500_REG_PROXCTRL0)); printf("RegProxCtrl1:%02x\r\n", sx9500.read_single(SX9500_REG_PROXCTRL1)); printf("RegProxCtrl2:%02x\r\n", sx9500.read_single(SX9500_REG_PROXCTRL2)); printf("RegProxCtrl3:%02x\r\n", sx9500.read_single(SX9500_REG_PROXCTRL3)); printf("RegProxCtrl4:%02x\r\n", sx9500.read_single(SX9500_REG_PROXCTRL4)); printf("RegProxCtrl5:%02x\r\n", sx9500.read_single(SX9500_REG_PROXCTRL5)); printf("RegProxCtrl6:%02x\r\n", sx9500.read_single(SX9500_REG_PROXCTRL6)); } else if (pcbuf[2] == 'a') { if (sx9500.get_active()) { sx9500.set_active(false); } else { sx9500.RegProxCtrl0.octet = sx9500.read_single(SX9500_REG_PROXCTRL0); sx9500.RegProxCtrl0.bits.sensor_en = 3; // CS0 and CS1 on sx9500.write(SX9500_REG_PROXCTRL0, sx9500.RegProxCtrl0.octet); sx9500.write(SX9500_REG_PROXCTRL6, 1); // threshold to 20 for CS1 release sx9500.write(SX9500_REG_IRQMSK, 0x60); // enable near and far interrupts sx9500.set_active(true); printf("RegProxCtrl0:%02x\r\n", sx9500.read_single(SX9500_REG_PROXCTRL0)); // sensor-enable and scan period } printf("(txen) active:%d\r\n", sx9500.get_active()); } else if (pcbuf[2] == 'R') { sx9500.reset(); } else if (pcbuf[2] == 'i') { if (pcbuf[3] != 0) { sscanf(pcbuf+3, "%x", &i); sx9500.write(SX9500_REG_IRQMSK, i); } printf("irqmsk:%02x\r\n", sx9500.read_single(SX9500_REG_IRQMSK)); } else if (pcbuf[2] == 't') { if (pcbuf[3] >= '0' && pcbuf[3] <= '9') { sscanf(pcbuf+3, "%d", &i); sx9500.write(SX9500_REG_PROXCTRL6, i); } printf("proxthresh:0x%x\r\n", sx9500.read_single(SX9500_REG_PROXCTRL6)); } else if (pcbuf[2] == 'p') { if (pcbuf[3] >= '0' && pcbuf[3] <= '9') { sscanf(pcbuf+2, "%d", &i); sx9500.RegProxCtrl0.bits.scan_period = i; sx9500.write(SX9500_REG_PROXCTRL0, sx9500.RegProxCtrl0.octet); } sx9500.RegProxCtrl0.octet = sx9500.read_single(SX9500_REG_PROXCTRL0); printf("scan period:%d\r\n", sx9500.RegProxCtrl0.bits.scan_period); } } */