Yuki Abe / Mbed 2 deprecated IM920_sample

Dependencies:   IM920 mbed

Fork of IM920_sample by Suga koubou

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers main.cpp Source File

main.cpp

00001 #include "mbed.h"
00002 #include "IM920.h"
00003 
00004 DigitalOut myled(LED1);
00005 Serial pc(USBTX, USBRX);
00006 IM920 im920(p28, p27, p29, p30);
00007 
00008 void callback () {
00009     int i;
00010     char buf[65];
00011 
00012     i = im920.recv(buf, 64);
00013     buf[i] = 0;
00014     printf("recv: '%s' (%d)\r\n", buf, i);
00015 }
00016 
00017 int main() {
00018     int i = 0;
00019     char buf[65];
00020 
00021     pc.baud(115200);
00022     pc.printf("*** IM920\r\n");
00023     im920.init();
00024     im920.attach(callback);
00025     myled = 1;
00026 
00027     for (;;) {
00028         im920.poll();
00029         if (pc.readable()) {
00030             char c = pc.getc();
00031             if (c == '\r') {
00032                 buf[i] = 0;
00033                 printf("send: %s\r\n", buf);
00034                 im920.send(buf, i);
00035                 i = 0;
00036             } else
00037             if (i < 64) {
00038                 buf[i] = c;
00039                 i ++;
00040             }
00041             
00042         }
00043     }
00044 }
00045