remote control
Dependencies: mbed BufferedSerial drorfilter
Diff: main.cpp
- Revision:
- 0:2d9632685074
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/main.cpp Sat May 02 10:50:51 2020 +0000 @@ -0,0 +1,42 @@ +#include "mbed.h" +#include "Filter.hpp" +#include "BufferedSerial.h" +//------------------------------------ +// Hyperterminal configuration +// 9600 bauds, 8-bit data, no parity +//------------------------------------ + +BufferedSerial pc(SERIAL_TX, SERIAL_RX); +BufferedSerial xbee(PA_9, PA_10); +DigitalOut myled(LED1); +char read_data[3] = {0,0,0}; +int num = 0; +Filter wfilter(0.8, 0); +unsigned long long numRx = 0; +int main() +{ + pc.baud(57600); + xbee.baud(57600); + int numRx; + while(1) { + numRx = 0; + int numchar = 3; + if (xbee.readable()){ + int count=0; + while(numchar!=count) { + if(xbee.readable()) { + read_data[count] = xbee.getc()-48; + count++; + } + } + numRx = (read_data[0] * 100) + (read_data[1] * 10) + (read_data[2]); + pc.printf("the num is %d ", numRx); + pc.printf("the filterd num is %.4f", wfilter.Applyfilter(numRx)); + + } + else{ + pc.printf("NO DATA\r\n"); + } + wait(1); + } +} \ No newline at end of file