diff --git a/README.md b/README.md index 3faaccd..3aed4f4 100644 --- a/README.md +++ b/README.md @@ -43,11 +43,25 @@ Now, when you build your project, PlatformIO will download the library from the #include ``` -2. Create a TouchHandler object, providing an array of touch sensor pins and the number of pins. +2. Create a TouchHandler object by providing an array of touch sensor pins, + the number of pins, and a configuration structure specifying parameters + like sample period, initialization period, filter period, sensitivity, + factor, offset, and the number of initial samples. ```cpp const int touchPins[NUM_TOUCH_PINS] = {4, 12, 13, 14, 15, 27, 32, 33}; -TouchHandler touchHandler(touchPins, NUM_TOUCH_PINS); + +TouchConfig config = { + .samplePeriod = 10, // in milliseconds. + .initPeriod = 5000, // Initialization period in milliseconds. + .filterPeriod = 10000, // Filtering period in milliseconds. + .sensitivity = 0.5f, // Sensitivity factor for touch detection. + .factor = 12.0f, // Scaling factor used in threshold calculation. + .offset = 40.0f, // Offset added to baseline for threshold detection. + .numInitSamples = 50 // Number of samples collected during initialization. +}; + +TouchHandler touchHandler(touchPins, NUM_TOUCH_PINS, config); ``` 3. In the setup() function, call the begin() method on the TouchHandler object. @@ -137,7 +151,18 @@ Here is an example of how to use the TouchHandler library in a simple Arduino sk const int NUM_TOUCH_PINS = 8; const int touchPins[NUM_TOUCH_PINS] = {4, 12, 13, 14, 15, 27, 32, 33}; -TouchHandler touchHandler(touchPins, NUM_TOUCH_PINS); + +TouchConfig config = { + .samplePeriod = 10, // in milliseconds. + .initPeriod = 5000, // Initialization period in milliseconds. + .filterPeriod = 10000, // Filtering period in milliseconds. + .sensitivity = 0.5f, // Sensitivity factor for touch detection. + .factor = 12.0f, // Scaling factor used in threshold calculation. + .offset = 40.0f, // Offset added to baseline for threshold detection. + .numInitSamples = 50 // Number of samples collected during initialization. +}; + +TouchHandler touchHandler(touchPins, NUM_TOUCH_PINS, config); void setup() { Serial.begin(115200); @@ -206,4 +231,4 @@ The TouchHandler library is released under the MIT License. This means that you ## Disclaimer -This code and documentation have been generated using ChatGPT, a large language model based on OpenAI's GPT-4 architecture. While efforts have been made to provide accurate information and guidance, please be aware that the content may not be perfect and should be used at your own discretion. \ No newline at end of file +This code and documentation have been generated using ChatGPT, a large language model based on OpenAI's GPT-4 architecture. While efforts have been made to provide accurate information and guidance, please be aware that the content may not be perfect and should be used at your own discretion. diff --git a/examples/turn_on_led_on_touch/main.cpp b/examples/turn_on_led_on_touch/main.cpp index 56a56ee..9caefe7 100644 --- a/examples/turn_on_led_on_touch/main.cpp +++ b/examples/turn_on_led_on_touch/main.cpp @@ -10,7 +10,19 @@ const int touchPins[] = {4, 12, 13, 14, 15, 27, 32, 33}; const int numTouchPins = sizeof(touchPins) / sizeof(touchPins[0]); -TouchHandler touchHandler(touchPins, numTouchPins); +// Configure touch parameters +TouchConfig config = { + .samplePeriod = 10, // in milliseconds + .initPeriod = 5000, // Initialization period in milliseconds + .filterPeriod = 10000, // Filtering period in milliseconds + .sensitivity = 0.5f, // Sensitivity factor for touch detection + .factor = 12.0f, // Scaling factor used in threshold calculation + .offset = 40.0f, // Offset added to baseline for threshold detection + .numInitSamples = 50 // Number of samples collected during initialization +}; + +// Initialize TouchHandler with touch pins, number of pins, and configuration +TouchHandler touchHandler(touchPins, numTouchPins, config); void setup() { Serial.begin(115200); @@ -21,7 +33,7 @@ void setup() { void loop() { touchHandler.update(); - for (int i = 0; i < numTouchPins; i++) { + for (int i = 0; i < numTouchPins; ++i) { if (touchHandler.isTouched(i)) { digitalWrite(LED_PIN, HIGH); Serial.print("Touch pin ");