VISHAY CNY70 reflective sensor library

Dependents:   FRC_2018 0hackton_08_06_18 lib_FRC_2019 lib_FRC_2019 ... more

Files at this revision

API Documentation at this revision

Comitter:
haarkon
Date:
Thu May 31 17:26:08 2018 +0000
Parent:
2:9dec6e856355
Commit message:
Tested CNY70 library

Changed in this revision

CNY70.cpp Show annotated file Show diff for this revision Revisions of this file
CNY70.h Show annotated file Show diff for this revision Revisions of this file
--- a/CNY70.cpp	Tue May 22 17:15:44 2018 +0000
+++ b/CNY70.cpp	Thu May 31 17:26:08 2018 +0000
@@ -5,9 +5,15 @@
 
 double CNY70::getVoltage (void)
 {
-    return _sensor.read()* 3.3;
+    return (double)_sensor.read()* 3.3;
+}
+
+int CNY70::whatAmIOn (void)
+{
+    if (_sensor.read()>0.5f)    return 0;
+    else                        return 1;
 }
 
 CNY70::operator double() {
-    return _sensor.read()* 3.3;
+    return (double)_sensor.read()* 3.3;
 }
--- a/CNY70.h	Tue May 22 17:15:44 2018 +0000
+++ b/CNY70.h	Thu May 31 17:26:08 2018 +0000
@@ -61,6 +61,13 @@
      */
     double getVoltage (void);
 
+    /**
+     * Return the type of the ground (blue carpet or white stripe)
+     *
+     * @return 0 over a blue carpet, 1 over a PVC white stripe
+     */
+    int whatAmIOn (void);
+
     /** 
      * A short hand of getVoltage
      */