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.
Diff: main.cpp
- Revision:
- 1:2ee96e43619f
- Parent:
- 0:bfb59ebe2f4a
- Child:
- 2:b3703b128b14
--- a/main.cpp Mon Feb 10 07:47:19 2014 +0000
+++ b/main.cpp Mon Feb 10 07:51:06 2014 +0000
@@ -1,6 +1,7 @@
#include "mbed.h"
Serial pc(USBTX,USBRX) ;
+Serial zw(p9,p10) ;
InterruptIn TRG(p30) ;
DigitalOut TRG_OUT(p13) ;
DigitalOut led1(LED1),led2(LED2),led3(LED3),led4(LED4);
@@ -26,8 +27,14 @@
}
}
+char zwrxbuf[1024] = "---------------------------" ;
+int zwrxctr = 0;
+
+char sendbuf[] = "************" ;
+
int main() {
pc.baud(115200) ;
+ zw.baud(115200) ;
TRG.mode(PullUp) ;
TRG.fall(trgon);
timer.attach(timer1ms,0.001) ; // 1ms
@@ -37,7 +44,7 @@
if (onctr >= 20) {
onctr = 0 ;
led4 = !led4 ;
- pc.printf(":%d\r\n",edgectr) ;
+ pc.printf("%d,%s\r\n",edgectr,sendbuf) ;
} else if (onctr >= 10) {
TRG_OUT = 0 ;
} else {
@@ -48,7 +55,28 @@
if (pc.readable()) {
if (pc.getc() == '*') {
edgectr = 0 ;
- pc.printf("+%d\r\n",edgectr) ;
+ for(int i=0;i<sizeof(sendbuf)-1;i++) {
+ sendbuf[i] = '*' ;
+ }
+ pc.printf("%d,%s\r\n",edgectr,sendbuf) ;
+ }
+ }
+
+ // read zw
+ if (zw.readable()) {
+ int c = zw.getc() ;
+ if (c != 0x0D) {
+ zwrxbuf[zwrxctr] = c ;
+ zwrxctr = (zwrxctr + 1) & 0xFF ;
+ led3 = !led3 ;
+ } else {
+ // copy
+ for(int i=0;i<sizeof(sendbuf)-1;i++) {
+ sendbuf[i] = zwrxbuf[i] ;
+ }
+ // reset
+ zwrxctr = 0 ;
+ led2 = !led2 ;
}
}
}