diff --git a/docs/api.md b/docs/api.md new file mode 100644 index 0000000..5164de1 --- /dev/null +++ b/docs/api.md @@ -0,0 +1,254 @@ +# MCHPTouch library + +## Methods + +### `QtouchClass()` + +Constructor, make the instance of the object. + +Already accessible by using `TOUCH` object + +#### Syntax + +``` +QtouchClass TOUCH; +``` + +#### See also + +* [begin()](#begin) +* [poll()](#poll) + + +### `begin()` + +Initializes Qtouch sensors + +#### Returns +`true` in success, `false` if it fails. + +#### Syntax + +``` +TOUCH.begin() +``` + +#### Example + +``` +#include + +void setup() +{ + if(TOUCH.begin()){ + // Everything OK + }else{ + // Failure + } +} + +void loop() {} +``` + +#### See also + +* [poll()](#attached) +* [read()](#read) + +### `available()` + +Checks for new values availability + +#### Syntax + +``` +TOUCH.available(); +``` + +#### Returns + 0 on no data, 1 on measure availability + +### `poll()` + +Polls the qotuch sensors for new measure. + +#### Syntax + +``` +TOUCH.poll(); +``` + +#### See also + +* [available()](#available) +* [read()](#read) + +### `read()` + +Querys the Qtouch and returns new touch measure. + +##### Syntax + +``` +TOUCH.read(sensor_id) +``` +#### Parameters + +* sensor_id : Sensor identificator + +##### Returns +0 - not activated +1 - activated +-1 - not found + +#### Example + +``` +#include "Arduino_MCHPTouch.h" + +void setup() +{ + Serial.begin(9600); + + // Qtouch initialization + if (!TOUCH.begin()) + { + Serial.println("Error in sensors initialization!"); + while (1); + } + Serial.println("Touch initialization Done!"); +} + +void loop() +{ + // polling the sensor for new measure + TOUCH.poll(); + + // Checks if new data are available + if (TOUCH.available()) + { + //reads senseors + Serial.print("Sensor 1 status: "); + Serial.println(TOUCH.read(0)); + Serial.print("Sensor 2 status: "); + Serial.println(TOUCH.read(1)); + Serial.print("Sensor 3 status: "); + Serial.println(TOUCH.read(2)); + Serial.print("Sensor 4 status: "); + Serial.println(TOUCH.read(3)); + Serial.print("Sensor 5 status: "); + Serial.println(TOUCH.read(4)); + Serial.println(); + } + delay(100); +} +``` + +#### See also + +* [read()](#read) +* [poll()](#poll) + + +### `setSensorsSensitivity()` + +Sets all the sensors sensitivity value, or to a specific sensor's. + +#### Syntax + +``` +TOUCH.setSensorSensitivty() +//TOUCH.setSensorSensitivty(btn_Channel, newSens) +``` + +#### Parameters + +* (optional) btn_channel : sensor's number, to change only that sensitivity +* newSens : new sensitivity from 3 to 100 + +#### See also + +* [getSensorsSensitivity()](#getSensorsSensitivity) +* [setSensorsHysteresis()](#setSensorsHysteresis) + +### `getSensorsSensitivity()` + +Querys the Qtouch and returns the configured Sensitivity, or from a specific sensor's +#### Syntax + +``` +TOUCH.getSensorsSensitivity() +``` + +#### Parameters + +* (optional) btn_channel : sensor's number, to get only that sensitivity + +#### See also + +* [setSensorsSensitivity()](#setSensorsSensitivity) + +### `setSensorsSensitivity()` + +Sets all the sensors sensitivity value, or to a specific sensor's. + +#### Syntax + +``` +TOUCH.setSensorSensitivty() +//TOUCH.setSensorSensitivty(btn_Channel, newSens) +``` + +#### Parameters + +* (optional) btn_channel : sensor's number, to change only that sensitivity +* newSens : new sensitivity from 3 to 100 + +#### See also + +* [getSensorsSensitivity()](#getSensorsSensitivity) +* [setSensorsHysteresis()](#setSensorsHysteresis) + + +### `getSensorsHysteresis()` + +Querys the Qtouch and returns the configured hysteresis + +#### Syntax + +``` +TOUCH.getSensorsHysteresis() +``` + +#### Returns + +Hysteresis + +#### See also + +* [setSensorsSensitivity()](#setSensorsSensitivity) + + +### `setSensorsHysteresis()` + +Querys the Qtouch and returns the configured hysteresis + +#### Syntax + +``` +TOUCH.setSensorsHysteresis(newHyst) +``` + +#### Parameteres + +newHyst: + - HYST_50 + - HYST_25 + - HYST_12_5 + - HYST_6_25 + - MAX_HYST + +#### See also + +* [getSensorsHysteresis()](#getSensorsHysteresis) +* [setSensorsSensitivity()](#setSensorsSensitivity) diff --git a/docs/readme.md b/docs/readme.md new file mode 100644 index 0000000..60ea4a4 --- /dev/null +++ b/docs/readme.md @@ -0,0 +1,31 @@ +# Arduino_MCHPTouch + +This library allows you to read touch sensors values from the [Arduino MKR](https://store.arduino.cc/arduino-mkr-wifi-1010) boards and the [Arduino Nano 33 IoT](https://store.arduino.cc/arduino-nano-33-iot). Touch sensing is a hardware capability of the SAMD21 processor. + +This library allows to configure and read capacitive touch sensors, using MicroChip Technology ([Qtouch](https://www.microchip.com/en-us/development-tools-tools-and-software/libraries-code-examples-and-more/qtouch-tools)) + +With this you will be able to configure the sensing of the capacitive pad by changing the distance of reading. +Also it allows to get the values with an easy and handy way. + +See the bundled [examples](examples/) for usage and visit the [Microchip Developer](https://microchipdeveloper.com/touch:start) website to learn more about touch sensing. + + +To use this library: + +``` +#include +``` + +## Circuit + +[Arduino MKR](https://store.arduino.cc/arduino-mkr-wifi-1010) +[Arduino Nano 33 IoT](https://store.arduino.cc/arduino-nano-33-iot) + + +## License + +This library is a wrapper around the MCHPTouch library by Microchip, which is bundled in binary form in this distribution in agreement with Microchip. + +> Microchip Technology Inc., provides the Microchip Touch Library software subject to the license terms contained at the link below.  By using the Microchip Touch Library, you acknowledge and agree to the terms of the license contained at the link below. [Microchip Touch Library License Agreement](Microchip%20Touch%20Library%20License%20Agreement%20-%20Arduino%20082420.pdf) + +The Arduino_MCHPTouch wrapper library is distributed under the terms of the MPL-2.0 license. \ No newline at end of file diff --git a/src/Arduino_MCHPTouch.cpp b/src/Arduino_MCHPTouch.cpp index 5ccc532..8dcd620 100644 --- a/src/Arduino_MCHPTouch.cpp +++ b/src/Arduino_MCHPTouch.cpp @@ -134,6 +134,19 @@ unsigned int QtouchClass::getSensorsSensitivity() return getSensitivity(); } +/******************************************************************************* + * Function Name : getSensorsSensitivity + * Description : Querys the Qtouch and returns the configured Sensitivity + * value from a specific sensor + * Input : btn_channel - sensor's number + * Return : The Sensitivity value + *******************************************************************************/ + +unsigned int QtouchClass::getSensorsSensitivity(unsigned int btn_channel) +{ + return getSensitivity(unsigned int btn_channel); +} + /******************************************************************************* * Function Name : getSensorsHysteresis * Description : Querys the Qtouch and returns the configured hysteresis diff --git a/src/touch.c b/src/touch.c index 3c39de8..cbfcea9 100644 --- a/src/touch.c +++ b/src/touch.c @@ -425,3 +425,7 @@ hysteresis_t getHysteresis() { unsigned int getSensitivity() { return _sensitivity; } + +unsigned int getSensitivity(unsigned int btn_channel) { + return _sensitivity_ch[btn_channel]; +}