remote control

Dependencies:   mbed BufferedSerial drorfilter

main.cpp

Committer:
drorbalbul
Date:
2020-05-02
Revision:
0:2d9632685074

File content as of revision 0:2d9632685074:

#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);
    }
}