Currently a giant piece of crap, this library is just a quick way to get cheap inputs out of scrap parts. I will fix it up eventually so if you decide to use it now you do so at your own risk. Also, if you are allergic to moronic library names you probably do not want to touch this :)

Files at this revision

API Documentation at this revision

Comitter:
Nakor
Date:
Mon Jan 31 00:00:35 2011 +0000
Child:
1:69d0b1c11c73
Commit message:
First commit.

Changed in this revision

theBadTouch.cpp Show annotated file Show diff for this revision Revisions of this file
theBadTouch.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/theBadTouch.cpp	Mon Jan 31 00:00:35 2011 +0000
@@ -0,0 +1,124 @@
+#include "mbed.h"
+#include "theBadTouch.h"
+
+
+theBadTouch::theBadTouch(PinName touchPin, PinName sink)
+{
+    _sensor = touchPin;
+    //_sink = sink;
+    _sink = new DigitalIn(sink);
+    _sink->mode(PullUp);
+    tracker1 = false;
+    tracker2 = false;
+    _touchFlag = 0x00;
+    falseCounter = 0;
+    t.start();
+    t_off.start();
+}
+
+
+
+/******************/
+/* Protected      */
+/******************/
+
+
+
+
+/******************/
+/* Public         */
+/******************/
+// _touchFlag
+// 0x00 = Free (untouched long enough to be available for instant touch)
+// 0x01 = being touched
+// 0x02 = Timing length of time sensor is untouched
+
+char theBadTouch::isTouch()
+{
+    if(falseCounter > 20)
+    {
+        _untouchedFlag = 0x01;
+        falseCounter = 0;
+        return 0x00;
+    }
+
+    if(badPlace() >= 1.0)
+    {
+        if(_untouchedFlag == 0x01)
+        {
+            _untouchedFlag = 0x00;
+            return 0x01;
+        }
+        else
+        {
+            t.reset();
+            for(int i = 0; i < 20; i++)
+            {
+                while(badPlace() >= 1.0)
+                {
+                    if(t.read_ms() > 300)
+                    {
+                        return 0x02;
+                    }
+                }
+            }
+        }
+    }
+    else
+    {
+        falseCounter++;
+        return 0x00;
+    }
+    
+    return 0x00;
+}
+
+bool theBadTouch::oldbadPlace()
+{
+    _precharge = new DigitalInOut(_sensor);
+    _precharge->output();
+    (*_precharge) = 1; 
+    _precharge->input();
+    _precharge->mode(PullNone);
+    delete _precharge;
+    wait_ms(10);
+    _sense = new AnalogIn(_sensor);
+    float value = *_sense;
+    delete _sense;
+
+    if(value >= 1.0)
+    {
+        _touchFlag = 0x01;
+        falseCounter = 0;
+        return true;
+    }
+    else
+    {
+        falseCounter++;
+    }
+ 
+    
+    if(falseCounter > 5)
+    {
+        _untouchedFlag = 0x01;
+        falseCounter = 0;
+    }
+    return false;
+}
+
+
+float theBadTouch::badPlace()
+{
+    _precharge = new DigitalInOut(_sensor);
+    _precharge->output();
+    (*_precharge) = 1; 
+    _precharge->input();
+    _precharge->mode(PullNone);
+    delete _precharge;
+    wait_ms(10);
+    _sense = new AnalogIn(_sensor);
+    float value = *_sense;
+    delete _sense;
+    
+    return value;
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/theBadTouch.h	Mon Jan 31 00:00:35 2011 +0000
@@ -0,0 +1,43 @@
+/* This is a touch sensing library.  If you don't have any buttons lying around but need
+ * user input, you may still have what you need.  A few capacitors, resistors, unused pins,
+ * and some wire and you've got yourself some capacitive input.
+ *
+ * This library (theBadTouch) by Aaron Goselin.  You are free to do what you like with this,
+ * but please keep credit in place.
+ * 2010 Aaron Goselin.
+ *
+ */
+
+#ifndef _TOUCHYMCTOUCHERTON_
+#define _TOUCHYMCTOUCHERTON_
+
+#include "mbed.h"
+
+
+class theBadTouch {
+
+public:
+
+
+    theBadTouch(PinName touchPin, PinName sink);
+    
+
+    bool oldbadPlace();
+    float badPlace();
+    char isTouch();
+
+protected:
+    DigitalIn * _sink;
+    DigitalInOut * _precharge;
+    AnalogIn * _sense;
+    PinName _sensor;
+    bool tracker1, tracker2;
+    Timer t, t_off;
+    char _touchFlag, _untouchedFlag;
+    int falseCounter;
+    
+
+    
+};
+
+#endif
\ No newline at end of file