|
| 1 | +# CapacitiveTouch Library |
| 2 | + |
| 3 | +The CapacitiveTouch Library is designed to simplify the use of capacitive touch sensors on Arduino UNO-R4 boards (Minima and WiFi). This library hides the low-level hardware details (CTSU, DTC, interrupts, etc.) and provides a simple, user-friendly API for beginners and educational projects. |
| 4 | + |
| 5 | +## Features |
| 6 | +- **Easy to Use API:** |
| 7 | + Initialize your sensor with just one constructor call and use simple methods to read sensor values and detect touches. |
| 8 | +- **Board Support:** |
| 9 | + Compatible with Arduino UNO-R4 Minima and UNO-R4 WiFi boards. |
| 10 | +- **Low-Level Abstraction:** |
| 11 | + All complex tasks (hardware setup, measurement control, interrupt management) are abstracted away so you can focus on your project. |
| 12 | + |
| 13 | +## Installation |
| 14 | +1. Copy `CapacitiveTouch.h` and `CapacitiveTouch.cpp` into your Arduino libraries folder. |
| 15 | +2. Restart your Arduino IDE so it recognizes the new library. |
| 16 | + |
| 17 | +## Compatible Pins |
| 18 | + |
| 19 | +### Arduino UNO-R4 Minima |
| 20 | +| Arduino Pin | Touch Sensor Channel (TS#) | Channel Control Index (CHAC idx) | Channel Control Bit Mask (CHAC val) | |
| 21 | +|--------------|----------------------------|----------------------------------|-------------------------------------| |
| 22 | +| D0 | 9 | 1 | (1 << 1) | |
| 23 | +| D1 | 8 | 1 | (1 << 0) | |
| 24 | +| D2 | 34 | 4 | (1 << 2) | |
| 25 | +| D3 | 13 | 1 | (1 << 5) | |
| 26 | +| D8 | 11 | 1 | (1 << 3) | |
| 27 | +| D9 | 2 | 0 | (1 << 2) | |
| 28 | +| D11 | 10 | 1 | (1 << 2) | |
| 29 | +| D13 | 12 | 1 | (1 << 4) | |
| 30 | +| A1 (D15) | 21 | 2 | (1 << 5) | |
| 31 | +| A2 (D16) | 22 | 2 | (1 << 6) | |
| 32 | +| LOVE_BUTTON | 0 | 0 | (1 << 0) | |
| 33 | + |
| 34 | +### Arduino UNO-R4 WiFi |
| 35 | +| Arduino Pin | Touch Sensor Channel (TS#) | Channel Control Index (CHAC idx) | Channel Control Bit Mask (CHAC val) | |
| 36 | +|--------------|----------------------------|----------------------------------|-------------------------------------| |
| 37 | +| D0 | 9 | 1 | (1 << 1) | |
| 38 | +| D1 | 8 | 1 | (1 << 0) | |
| 39 | +| D2 | 13 | 1 | (1 << 5) | |
| 40 | +| D3 | 34 | 4 | (1 << 2) | |
| 41 | +| D6 | 12 | 1 | (1 << 4) | |
| 42 | +| D8 | 11 | 1 | (1 << 3) | |
| 43 | +| D9 | 2 | 0 | (1 << 2) | |
| 44 | +| D11 | 7 | 0 | (1 << 7) | |
| 45 | +| D12 | 6 | 0 | (1 << 6) | |
| 46 | +| A1 (D15) | 21 | 2 | (1 << 5) | |
| 47 | +| A2 (D16) | 22 | 2 | (1 << 6) | |
| 48 | +| LOVE_BUTTON | 27 | 3 | (1 << 3) | |
| 49 | + |
| 50 | +> **Note:** Only the above pins are supported. Other pins are not configured for capacitive touch sensing. |
| 51 | +
|
| 52 | +## Usage Example |
| 53 | + |
| 54 | +```cpp |
| 55 | +#include "CapacitiveTouch.h" |
| 56 | + |
| 57 | +// Instantiate a capacitive touch sensor using the LOVE_BUTTON macro. |
| 58 | +CapacitiveTouch ct = CapacitiveTouch(LOVE_BUTTON); |
| 59 | + |
| 60 | +void setup() { |
| 61 | + Serial.begin(9600); |
| 62 | + ct.begin(); |
| 63 | + ct.setThreshold(500); // Adjust threshold (lower values increase sensitivity) |
| 64 | + Serial.println("CapacitiveTouch Library: LOVE Button test"); |
| 65 | +} |
| 66 | + |
| 67 | +void loop() { |
| 68 | + int sensorValue = ct.read(); |
| 69 | + Serial.print("Raw Value: "); |
| 70 | + Serial.println(sensorValue); |
| 71 | + |
| 72 | + if (ct.isTouched()) { |
| 73 | + Serial.println("LOVE button touched!"); |
| 74 | + } |
| 75 | + delay(100); |
| 76 | +} |
0 commit comments