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.
Revision 0:cdbd21489e81, committed 2010-11-30
- Comitter:
- bzhang10
- Date:
- Tue Nov 30 22:03:27 2010 +0000
- Commit message:
Changed in this revision
--- /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