Bing Zhang / Mbed 2 deprecated TouchSense

Dependencies:   mbed

Files at this revision

API Documentation at this revision

Comitter:
bzhang10
Date:
Tue Nov 30 22:03:27 2010 +0000
Commit message:

Changed in this revision

main.cpp Show annotated file Show diff for this revision Revisions of this file
mbed.bld Show annotated file Show diff for this revision Revisions of this file
sense.cpp Show annotated file Show diff for this revision Revisions of this file
sense.h Show annotated file Show diff for this revision Revisions of this file
touch0.cpp Show annotated file Show diff for this revision Revisions of this file
touch0.h Show annotated file Show diff for this revision Revisions of this file
touch1.cpp Show annotated file Show diff for this revision Revisions of this file
touch1.h Show annotated file Show diff for this revision Revisions of this file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp	Tue Nov 30 22:03:27 2010 +0000
@@ -0,0 +1,52 @@
+#include "mbed.h"
+#include "touch0.h"
+#include "touch1.h"
+#include "sense.h"
+#define numsamples 1
+//DigitalOut myled0(LED1);
+//DigitalOut myled1(LED2);
+DigitalOut myled2(LED3);
+DigitalOut myled3(LED4);
+Serial pc(USBTX, USBRX); // tx, rx
+
+int main() {
+    char r='n';
+    int sp;
+    while (1) {
+        int match=1;
+        r=pc.getc();
+        while (r!='S') {
+            r=pc.getc();
+        }
+        while ((r!='E')&(match==1)) {
+//           pc.printf("abc");
+            do {
+                r=pc.getc();
+            } while   ((r!='E')&(r!='0')&(r!='1'));
+            if (r=='E') {
+                break;
+            }
+            sp=sense();
+            if (sp==2) {
+                match=2;
+                break;
+            } else {
+                if (((sp==1)&(r=='1'))^((sp==0)&(r=='0')))
+                    match=1;
+                else
+                    match=0;
+            }
+        }
+        switch (match) {
+            case 0:
+                pc.printf("HOST ERROR \n\r");
+                break;
+            case 1:
+                pc.printf("MATCH \n\r");
+                break;
+            case 2:
+                pc.printf("Touch Error \n\r");
+                break;
+        }
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/mbed.bld	Tue Nov 30 22:03:27 2010 +0000
@@ -0,0 +1,1 @@
+http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sense.cpp	Tue Nov 30 22:03:27 2010 +0000
@@ -0,0 +1,43 @@
+#include "mbed.h"
+#include "touch0.h"
+#include "touch1.h"
+#define numsamples 1
+DigitalOut myled0(LED1);
+DigitalOut myled1(LED2);
+int sense() {
+    int TS[2];
+    while (1) {
+        TS[0]=touchSense0();
+        TS[1]=touchSense1();
+        if (TS[0]*TS[1]==1) {
+            return 2;
+        } else {
+            if (TS[0]==1) {
+                while (TS[0]==1) {
+                    wait (0.5);
+                    TS[0]=touchSense0();
+                    TS[1]=touchSense1();
+                    if (TS[0]*TS[1]==1) {
+                        return 2;
+                    }
+                }
+                myled0=!myled0;
+                return 0;
+            } else {
+                if (TS[1]==1) {
+                    while (TS[1]==1) {
+                        wait (0.5);
+                        TS[0]=touchSense0();
+                        TS[1]=touchSense1();
+                        if (TS[0]*TS[1]==1) {
+                            return 2;
+                        }
+                    }
+                    myled1=!myled1;
+                    return 1;
+                }
+            }
+        }
+        wait(0.005);
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/sense.h	Tue Nov 30 22:03:27 2010 +0000
@@ -0,0 +1,1 @@
+int sense(void);
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/touch0.cpp	Tue Nov 30 22:03:27 2010 +0000
@@ -0,0 +1,20 @@
+#include "mbed.h"
+
+#define numsamples 1
+
+AnalogIn input(p20);
+DigitalIn charger(p19);
+DigitalOut ground(p18);
+
+int touchSense0(void) {
+    float sample;
+    ground = 0;
+    charger.mode(PullUp);
+    charger.mode(PullNone);
+    sample=input.read();
+    if (sample < 0.3) {
+        return 1;
+    } else {
+        return 0;
+    }
+}
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/touch0.h	Tue Nov 30 22:03:27 2010 +0000
@@ -0,0 +1,1 @@
+int touchSense0(void);
\ No newline at end of file
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/touch1.cpp	Tue Nov 30 22:03:27 2010 +0000
@@ -0,0 +1,20 @@
+#include "mbed.h"
+
+#define numsamples 1
+
+AnalogIn input1(p15);
+DigitalIn charger1(p16);
+DigitalOut ground1(p17);
+
+int touchSense1(void) {
+    float sample;
+    ground1 = 0;
+    charger1.mode(PullUp);
+    charger1.mode(PullNone);
+    sample=input1.read();
+    if (sample < 0.3) {
+        return 1;
+    } else {
+        return 0;
+    }
+}
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/touch1.h	Tue Nov 30 22:03:27 2010 +0000
@@ -0,0 +1,1 @@
+int touchSense1(void);
\ No newline at end of file