Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mongoose-os-libs/esp32-touchpad
JS bindings for ESP32 touch pad sensor
https://github.com/mongoose-os-libs/esp32-touchpad
Last synced: 21 days ago
JSON representation
JS bindings for ESP32 touch pad sensor
- Host: GitHub
- URL: https://github.com/mongoose-os-libs/esp32-touchpad
- Owner: mongoose-os-libs
- License: other
- Created: 2017-11-08T15:23:38.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2021-12-15T00:17:13.000Z (almost 3 years ago)
- Last Synced: 2024-07-31T21:52:50.170Z (4 months ago)
- Language: JavaScript
- Size: 9.77 KB
- Stars: 6
- Watchers: 5
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
- awesome-mongoose-os - esp32-touchpad - JS bindings for ESP32 touch pad sensor (Awesome Mongoose OS [![Awesome](https://awesome.re/badge.svg)](https://awesome.re) / Official Libraries)
README
# JS bindings for ESP32 touch pad sensor
## Overview
This library provides JavaScript bindings for the ESP32 touch pad sensor.
The JS API largely mirrors the [C API](https://github.com/espressif/esp-idf/blob/master/components/driver/include/driver/touch_pad.h).## Examples
### Polling the sensor manually
```js
load('api_esp32_touchpad.js');// Touch sensors are numbered from 0 to 9.
// For convenience, TouchPad.GPIO map translates from GPIO number to sensor number.
let ts = TouchPad.GPIO[15];TouchPad.init();
TouchPad.setVoltage(TouchPad.HVOLT_2V4, TouchPad.LVOLT_0V8, TouchPad.HVOLT_ATTEN_1V5);
TouchPad.config(ts, 0);
Timer.set(1000 /* 1 sec */, Timer.REPEAT, function() {
let tv = TouchPad.read(ts);
print('Sensor', ts, 'value', tv);
}, null);```
### Using interrupts
```js
load('api_esp32_touchpad.js');// Touch sensors are numbered from 0 to 9.
// For convenience, TouchPad.GPIO map translates from GPIO number to sensor number.
let ts = TouchPad.GPIO[15];TouchPad.init();
TouchPad.filterStart(10);
TouchPad.setMeasTime(0x1000, 0xffff);
TouchPad.setVoltage(TouchPad.HVOLT_2V4, TouchPad.LVOLT_0V8, TouchPad.HVOLT_ATTEN_1V5);
TouchPad.config(ts, 0);
Sys.usleep(100000); // wait a bit for initial filtering.
let noTouchVal = TouchPad.readFiltered(ts);
let touchThresh = noTouchVal * 2 / 3;
print('Sensor', ts, 'noTouchVal', noTouchVal, 'touchThresh', touchThresh);
TouchPad.setThresh(ts, touchThresh);
TouchPad.isrRegister(function(st) {
// st is a bitmap with 1 bit per sensor.
let val = TouchPad.readFiltered(ts);
print('Status:', st, 'Value:', val);
}, null);
TouchPad.intrEnable();
```