XIAOHUI TAO / Mbed 2 deprecated hw2_protothread
Committer:
taoxh
Date:
Tue Nov 30 23:53:06 2010 +0000
Revision:
0:ee91220d7bea
HW2 PROTOTHREAD

Who changed what in which revision?

UserRevisionLine numberNew contents of line
taoxh 0:ee91220d7bea 1 #include "mbed.h"
taoxh 0:ee91220d7bea 2
taoxh 0:ee91220d7bea 3 #define numsamples 1
taoxh 0:ee91220d7bea 4 int touchSense1(void);
taoxh 0:ee91220d7bea 5 int touchSense2(void);
taoxh 0:ee91220d7bea 6 int senderror ();
taoxh 0:ee91220d7bea 7 int senderror2 ();
taoxh 0:ee91220d7bea 8 int test1();
taoxh 0:ee91220d7bea 9 int test2();
taoxh 0:ee91220d7bea 10 DigitalOut myled1(LED1);
taoxh 0:ee91220d7bea 11 AnalogIn input1(p20);
taoxh 0:ee91220d7bea 12 DigitalIn charger1(p19);
taoxh 0:ee91220d7bea 13 DigitalOut ground1(p18);
taoxh 0:ee91220d7bea 14
taoxh 0:ee91220d7bea 15 DigitalOut myled2(LED2);
taoxh 0:ee91220d7bea 16 AnalogIn input2(p15);
taoxh 0:ee91220d7bea 17 DigitalIn charger2(p16);
taoxh 0:ee91220d7bea 18 DigitalOut ground2(p17);
taoxh 0:ee91220d7bea 19 Serial pc(USBTX, USBRX); // tx, rx
taoxh 0:ee91220d7bea 20 char str[40];
taoxh 0:ee91220d7bea 21 char str2[40];
taoxh 0:ee91220d7bea 22 int length=0;
taoxh 0:ee91220d7bea 23 int touchSense1(void) {
taoxh 0:ee91220d7bea 24 float sample;
taoxh 0:ee91220d7bea 25 ground1 = 0;
taoxh 0:ee91220d7bea 26 charger1.mode(PullUp);
taoxh 0:ee91220d7bea 27 charger1.mode(PullNone);
taoxh 0:ee91220d7bea 28 sample=input1.read();
taoxh 0:ee91220d7bea 29 if (sample < 0.3) {
taoxh 0:ee91220d7bea 30 return 1;
taoxh 0:ee91220d7bea 31 } else {
taoxh 0:ee91220d7bea 32 return 0;
taoxh 0:ee91220d7bea 33 }
taoxh 0:ee91220d7bea 34 }
taoxh 0:ee91220d7bea 35
taoxh 0:ee91220d7bea 36 int touchSense2(void) {
taoxh 0:ee91220d7bea 37 float sample;
taoxh 0:ee91220d7bea 38 ground2 = 0;
taoxh 0:ee91220d7bea 39 charger2.mode(PullUp);
taoxh 0:ee91220d7bea 40 charger2.mode(PullNone);
taoxh 0:ee91220d7bea 41 sample=input2.read();
taoxh 0:ee91220d7bea 42 if (sample < 0.3) {
taoxh 0:ee91220d7bea 43 return 1;
taoxh 0:ee91220d7bea 44 } else {
taoxh 0:ee91220d7bea 45 return 0;
taoxh 0:ee91220d7bea 46 }
taoxh 0:ee91220d7bea 47 }
taoxh 0:ee91220d7bea 48
taoxh 0:ee91220d7bea 49 int senderror () {
taoxh 0:ee91220d7bea 50 pc.printf("Touch Error");
taoxh 0:ee91220d7bea 51 return 0;
taoxh 0:ee91220d7bea 52 }
taoxh 0:ee91220d7bea 53
taoxh 0:ee91220d7bea 54 int senderror2 () {
taoxh 0:ee91220d7bea 55 pc.printf("Host Error");
taoxh 0:ee91220d7bea 56 return 0;
taoxh 0:ee91220d7bea 57 }
taoxh 0:ee91220d7bea 58
taoxh 0:ee91220d7bea 59
taoxh 0:ee91220d7bea 60
taoxh 0:ee91220d7bea 61
taoxh 0:ee91220d7bea 62
taoxh 0:ee91220d7bea 63 int test1()
taoxh 0:ee91220d7bea 64 {
taoxh 0:ee91220d7bea 65 int j=1000;
taoxh 0:ee91220d7bea 66 int judge=0;
taoxh 0:ee91220d7bea 67 for (int i=0;i<j;i++)
taoxh 0:ee91220d7bea 68 { if(touchSense1()) {judge=1;}}
taoxh 0:ee91220d7bea 69 return judge;
taoxh 0:ee91220d7bea 70 }
taoxh 0:ee91220d7bea 71
taoxh 0:ee91220d7bea 72 int test2()
taoxh 0:ee91220d7bea 73 {
taoxh 0:ee91220d7bea 74 int j=1000;
taoxh 0:ee91220d7bea 75 int judge=0;
taoxh 0:ee91220d7bea 76 for (int i=0;i<j;i++)
taoxh 0:ee91220d7bea 77 { if(touchSense2()) {judge=1;}}
taoxh 0:ee91220d7bea 78 return judge;
taoxh 0:ee91220d7bea 79 }