remote control

Dependencies:   mbed BufferedSerial drorfilter

Committer:
drorbalbul
Date:
Sat May 02 10:50:51 2020 +0000
Revision:
0:2d9632685074
remote control

Who changed what in which revision?

UserRevisionLine numberNew contents of line
drorbalbul 0:2d9632685074 1 #include "mbed.h"
drorbalbul 0:2d9632685074 2 #include "Filter.hpp"
drorbalbul 0:2d9632685074 3 #include "BufferedSerial.h"
drorbalbul 0:2d9632685074 4 //------------------------------------
drorbalbul 0:2d9632685074 5 // Hyperterminal configuration
drorbalbul 0:2d9632685074 6 // 9600 bauds, 8-bit data, no parity
drorbalbul 0:2d9632685074 7 //------------------------------------
drorbalbul 0:2d9632685074 8
drorbalbul 0:2d9632685074 9 BufferedSerial pc(SERIAL_TX, SERIAL_RX);
drorbalbul 0:2d9632685074 10 BufferedSerial xbee(PA_9, PA_10);
drorbalbul 0:2d9632685074 11 DigitalOut myled(LED1);
drorbalbul 0:2d9632685074 12 char read_data[3] = {0,0,0};
drorbalbul 0:2d9632685074 13 int num = 0;
drorbalbul 0:2d9632685074 14 Filter wfilter(0.8, 0);
drorbalbul 0:2d9632685074 15 unsigned long long numRx = 0;
drorbalbul 0:2d9632685074 16 int main()
drorbalbul 0:2d9632685074 17 {
drorbalbul 0:2d9632685074 18 pc.baud(57600);
drorbalbul 0:2d9632685074 19 xbee.baud(57600);
drorbalbul 0:2d9632685074 20 int numRx;
drorbalbul 0:2d9632685074 21 while(1) {
drorbalbul 0:2d9632685074 22 numRx = 0;
drorbalbul 0:2d9632685074 23 int numchar = 3;
drorbalbul 0:2d9632685074 24 if (xbee.readable()){
drorbalbul 0:2d9632685074 25 int count=0;
drorbalbul 0:2d9632685074 26 while(numchar!=count) {
drorbalbul 0:2d9632685074 27 if(xbee.readable()) {
drorbalbul 0:2d9632685074 28 read_data[count] = xbee.getc()-48;
drorbalbul 0:2d9632685074 29 count++;
drorbalbul 0:2d9632685074 30 }
drorbalbul 0:2d9632685074 31 }
drorbalbul 0:2d9632685074 32 numRx = (read_data[0] * 100) + (read_data[1] * 10) + (read_data[2]);
drorbalbul 0:2d9632685074 33 pc.printf("the num is %d ", numRx);
drorbalbul 0:2d9632685074 34 pc.printf("the filterd num is %.4f", wfilter.Applyfilter(numRx));
drorbalbul 0:2d9632685074 35
drorbalbul 0:2d9632685074 36 }
drorbalbul 0:2d9632685074 37 else{
drorbalbul 0:2d9632685074 38 pc.printf("NO DATA\r\n");
drorbalbul 0:2d9632685074 39 }
drorbalbul 0:2d9632685074 40 wait(1);
drorbalbul 0:2d9632685074 41 }
drorbalbul 0:2d9632685074 42 }