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.
capsense.cpp
- Committer:
- fionalin
- Date:
- 2022-07-12
- Revision:
- 1:40e5ac1119a6
- Parent:
- 0:4e3ad938564e
- Child:
- 2:d9745be6c253
File content as of revision 1:40e5ac1119a6:
#include <mbed.h> #include "capsense.h" CapSense::CapSense(PinName measure_pin, PinName square_pin) : cap_sense_measure(measure_pin), square_wave(square_pin), measured_this_cycle(false) {} bool CapSense::toggle() { bool last_signal = square_wave.read(); square_wave.write(!last_signal); if (!last_signal) { measured_this_cycle = false; timer.start(); } return !last_signal; } bool CapSense::try_measure() { if (cap_sense_measure.read() == 1 && !measured_this_cycle) { timer.stop(); last_measurement = timer.read(); measured_this_cycle = true; timer.reset(); return true; } return false; } long CapSense::read_measurement() { return last_measurement; }