Basic class to interface with a 3-pin capacitive proximity sensor

Files at this revision

API Documentation at this revision

Comitter:
snapo
Date:
Mon Nov 01 12:34:36 2021 +0000
Commit message:
basic class to interface quickly with a 3 pin capacitive proximity sensor;

Changed in this revision

CAPsensor.cpp Show annotated file Show diff for this revision Revisions of this file
CAPsensor.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CAPsensor.cpp	Mon Nov 01 12:34:36 2021 +0000
@@ -0,0 +1,16 @@
+#include "CAPsensor.h"
+
+capacitorSensor::capacitorSensor (PinName capSense):
+        capSense_ (capSense) {};
+
+
+//function measures the reading of the sensor and then prints to console the result.
+void capacitorSensor::capReading(){
+    capReadings_ = capSense_.read_u16();
+    
+    if (capReadings_ > 1000){
+        printf("Sensor is Pressed/Activated \n");
+        } else { 
+            printf("Sensor is NOT Pressed/Activated \n");
+        }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/CAPsensor.h	Mon Nov 01 12:34:36 2021 +0000
@@ -0,0 +1,15 @@
+#pragma once
+#include "mbed.h"
+
+class capacitorSensor {
+    
+    AnalogIn capSense_;
+    int capReadings_;
+    
+public:
+    //ensure the PinName included is one of the analog pins else the class will function incorrectly.
+    capacitorSensor (PinName capSense);
+    void capReading();
+
+
+};
\ No newline at end of file