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.
Dependencies: mbed
main.cpp
- Committer:
- pmic
- Date:
- 2019-08-13
- Revision:
- 0:03153e3cb89f
- Child:
- 1:ce38967a0d22
File content as of revision 0:03153e3cb89f:
#include "mbed.h"
#include "IIR_filter.h"
/* Notes pmic 13.08.2019:
-
*/
// nt baudrate = 115200;
Serial pc(SERIAL_TX, SERIAL_RX); // serial connection via USB - programmer
Timer t; // timer to analyse Button
Timer twhile; // timer for time measurement (usage in while(1), without timer attached)
Serial TFmini(PC_10, PC_11); // TX, RX
int dist; //actual distance measurements of LiDAR
int strength; //signal strength of LiDAR
int check; //save check value
int i;
char uart[9]; //save data measured by LiDAR
const int HEADER=0x59; //frame header of data package
volatile char c;
void onCharReceived()
{
c = TFmini.getc();
}
int k;
bool was_readable;
// float Ts = 0.05f; // ??? sample time of main loop, 20 Hz
// IIR_filter pt1(0.2f, Ts, 1.0f);
// float distf = 0.0f;
// float strengthf = 0.0f;
// main program and control loop
// -----------------------------------------------------------------------------
int main()
{
pc.baud(115200); // for serial comm. to pc
TFmini.baud(115200); // for serial comm. from TFmini
k = 0;
TFmini.attach(&onCharReceived, Serial::RxIrq);
// was_readable = false;
//pt1.reset(0.0f);
twhile.start(); // timer for time measurement (usage in while(1), without timer attached)
while(1) {
was_readable = true;
if (TFmini.readable()) { //check if serial port has data input
was_readable = true;
/*if(TFmini.getc() == HEADER) { //assess data package frame header 0x59
uart[0]=HEADER;
if (TFmini.getc() == HEADER) { //assess data package frame header 0x59
uart[1] = HEADER;
for (i = 2; i < 9; i++) { //save data in array
uart[i] = TFmini.getc();
}
check = uart[0] + uart[1] + uart[2] + uart[3] + uart[4] + uart[5] + uart[6] + uart[7];
if (uart[8] == (check & 0xff)) { //verify the received data as per protocol
dist = uart[2] + uart[3] * 256; //calculate distance value
strength = uart[4] + uart[5] * 256; //calculate signal strength value
}
}
}*/
} else {
was_readable = false;
}
// distf = pt1((float)dist);
k++;
// if(was_readable) pc.printf("%10i was readable\r\n", k);
// else pc.printf("%10i was not readable\r\n", k);
// if( TFmini.readable()) pc.printf("%10i %10i\r\n", k, TFmini.getc());
pc.printf("%10i %10i\r\n", k, (int)c);
//pc.printf("%10i %10.6e %10i\r\n", k, twhile.read(), dist);
//wait_ms(100);
}
}