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:c0d343a5025a, committed 2010-11-30
- Comitter:
- bzhang10
- Date:
- Tue Nov 30 22:04:12 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 |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/main.cpp Tue Nov 30 22:04:12 2010 +0000
@@ -0,0 +1,137 @@
+#include "mbed.h"
+#define numsamples 1
+
+AnalogIn input(p20);
+DigitalIn charger(p19);
+DigitalOut ground(p18);
+AnalogIn input1(p15);
+DigitalIn charger1(p16);
+DigitalOut ground1(p17);
+DigitalOut myled0(LED1);
+DigitalOut myled1(LED2);
+DigitalOut myled2(LED3);
+DigitalOut myled3(LED4);
+Serial pc(USBTX, USBRX); // tx, rx
+int sense();
+int touchSense0();
+int touchSense1();
+char r[100];
+int match=3;
+void foreground() {
+ int i=0;
+ pc.printf("cc");
+ do {
+ r[0]=pc.getc();
+ } while (r[0]!='s');
+ while (r[i]!='e') {
+ i++;
+ r[i]=pc.getc();
+ // pc.printf("%c",r[i]);
+ }
+ match=1;
+ pc.printf("%d",match);
+ return;
+}
+
+int main() {
+ int sp;
+ pc.attach(&foreground);
+ while (1) {
+ int i=1;
+ pc.printf("tt");
+ while ((r[i]!='e')&(match==1)) {
+ sp=sense();
+ pc.printf("WWW");
+ if (sp==2) {
+ match=2;
+ break;
+ } else {
+ if (((sp==1)&(r[i]=='1'))^((sp==0)&(r[i]=='0')))
+ match=1;
+ else
+ match=0;
+ }
+ i++;
+ }
+ switch (match) {
+ case 0:
+ pc.printf("HOST ERROR \n\r");
+ match=3;
+ i=1;
+ break;
+ case 1:
+ pc.printf("MATCH \n\r");
+ match=3;
+ i=1;
+ break;
+ case 2:
+ pc.printf("Touch Error \n\r");
+ match=3;
+ i=1;
+ break;
+ }
+ }
+}
+
+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);
+ }
+}
+
+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;
+ }
+}
+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;
+ }
+}
\ No newline at end of file
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/mbed.bld Tue Nov 30 22:04:12 2010 +0000 @@ -0,0 +1,1 @@ +http://mbed.org/users/mbed_official/code/mbed/builds/e2ac27c8e93e