Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
Dependencies: mbed
MPR121 Class Reference
Using the Sparkfun SEN-10250 BoB. More...
#include <MPR121.h>
Public Types | |
| enum | MPR121_ADDR { ADDR_VSS = 0x5A, ADDR_VDD, ADDR_SCL, ADDR_SDA } |
Possible terminations for the ADDR pin. More... | |
| enum | MPR121_REGISTER |
The device register map. More... | |
Public Member Functions | |
| MPR121 (I2C &i2c, InterruptIn &pin, MPR121_ADDR i2c_addr) | |
| Create the MPR121 object. | |
| MPR121 (I2C &i2c, MPR121_ADDR i2c_addr) | |
| Create the MPR121 object. | |
| void | init (void) |
| Clear state variables and initilize the dependant objects. | |
| void | enable (void) |
| Allow the IC to run and collect user input. | |
| void | disable (void) |
| Stop the IC and put into low power mode. | |
| uint32_t | isPressed (void) |
| Determine if a new button press event occured Upon calling the state is cleared until another press is detected. | |
| uint16_t | buttonPressed (void) |
| Get the electrode status (ELE12 ... | |
| void | registerDump (Serial &obj) const |
| print the register map and values to the console | |
| void | registerDump (void) const |
| print the register map and values to the console | |
| void | writeRegister (MPR121_REGISTER const reg, uint8_t const data) const |
| Write to a register (exposed for debugging reasons) Note: most writes are only valid in stop mode. | |
| uint8_t | readRegister (MPR121_REGISTER const reg) const |
| Read from a register (exposed for debugging reasons) | |
Detailed Description
Using the Sparkfun SEN-10250 BoB.
Example:
#include "mbed.h" #include "MPR121.h" Serial pc(USBTX, USBRX); DigitalOut myled(LED1); #if defined TARGET_LPC1768 || TARGET_LPC11U24 I2C i2c(p28, p27); InterruptIn irq(p26); MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS ); #elif defined TARGET_KL25Z I2C i2c(PTC9, PTC8); InterruptIn irq(PTA5); MPR121 touch_pad(i2c, irq, MPR121::ADDR_VSS ); #else #error TARGET NOT TESTED #endif int main() { touch_pad.init(); touch_pad.enable(); while(1) { if(touch_pad.isPressed()) { uint16_t button_val = touch_pad.buttonPressed(); printf("button = 0x%04x\n", button_val); myled = (button_val>0) ? 1 : 0; } } }
API for the MPR121 capacitive touch IC
Definition at line 74 of file MPR121.h.
Member Enumeration Documentation
| enum MPR121_ADDR |
| enum MPR121_REGISTER |
Constructor & Destructor Documentation
| MPR121 | ( | I2C & | i2c, |
| InterruptIn & | pin, | ||
| MPR121_ADDR | i2c_addr | ||
| ) |
Create the MPR121 object.
- Parameters:
-
i2c - A defined I2C object pin - A defined InterruptIn object i2c_addr - Connection of the address line
Definition at line 28 of file MPR121.cpp.
| MPR121 | ( | I2C & | i2c, |
| MPR121_ADDR | i2c_addr | ||
| ) |
Create the MPR121 object.
- Parameters:
-
i2c - A defined I2C object i2c_addr - Connection of the address line
Definition at line 37 of file MPR121.cpp.
Member Function Documentation
| uint16_t buttonPressed | ( | void | ) |
Get the electrode status (ELE12 ...
ELE0 -> b15 xxx b11 ... b0 The buttons are bit mapped. ELE0 = b0 ... ELE11 = b11 b12 ... b15 undefined
- Returns:
- The state of all buttons
Definition at line 134 of file MPR121.cpp.
| void disable | ( | void | ) |
Stop the IC and put into low power mode.
Definition at line 115 of file MPR121.cpp.
| void enable | ( | void | ) |
Allow the IC to run and collect user input.
Definition at line 100 of file MPR121.cpp.
| void init | ( | void | ) |
Clear state variables and initilize the dependant objects.
Definition at line 46 of file MPR121.cpp.
| uint32_t isPressed | ( | void | ) |
Determine if a new button press event occured Upon calling the state is cleared until another press is detected.
- Returns:
- 1 if a press has been detected since the last call, 0 otherwise
Definition at line 129 of file MPR121.cpp.
| uint8_t readRegister | ( | MPR121_REGISTER const | reg ) | const |
Read from a register (exposed for debugging reasons)
- Parameters:
-
reg - The register to read from
- Returns:
- The register contents
Definition at line 205 of file MPR121.cpp.
| void registerDump | ( | void | ) | const |
print the register map and values to the console
Definition at line 155 of file MPR121.cpp.
| void registerDump | ( | Serial & | obj ) | const |
print the register map and values to the console
- Parameters:
-
obj - a Serial object that prints to a console
Definition at line 143 of file MPR121.cpp.
| void writeRegister | ( | MPR121_REGISTER const | reg, |
| uint8_t const | data | ||
| ) | const |
Write to a register (exposed for debugging reasons) Note: most writes are only valid in stop mode.
- Parameters:
-
reg - The register to be written data - The data to be written
Definition at line 191 of file MPR121.cpp.
Generated on Sat Sep 16 2023 00:48:02 by
1.7.2