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
Diff: main.cpp
- Revision:
- 6:4a3ab00525f4
- Parent:
- 4:d60840a04ddc
--- a/main.cpp Thu Aug 15 12:54:11 2019 +0000
+++ b/main.cpp Fri Dec 06 10:15:35 2019 +0000
@@ -8,19 +8,16 @@
Serial pc(SERIAL_TX, SERIAL_RX); // serial connection via USB - programmer
InterruptIn Button(USER_BUTTON); // User Button
Ticker LoopTimer; // interrupt for control loop
-Timer t; // timer to analyse Button
RawSerial uart(PC_10, PC_11);
TFmini tfmini(uart);
-int16_t dist; // actual distance measurements of LiDAR
-int16_t strength;
-int16_t distOld; // actual distance measurements of LiDAR
-bool receiveComplete;
+float dist; // actual distance measurements of LiDAR
+float strength;
int k;
bool doRun;
-float Ts = 0.010f; // sample time of main loop, 50 Hz
+float Ts = 0.02f; // sample time of main loop
float dt;
Timer twhile; // timer for time measurement (usage in while(1), without timer attached)
@@ -33,15 +30,15 @@
// -----------------------------------------------------------------------------
int main()
{
- pc.baud(115200); // for serial comm.
+ pc.baud(2000000); // for serial comm.
LoopTimer.attach(&updateLoop, Ts); // attach loop to timer interrupt
Button.fall(&pressed); // attach key pressed function
Button.rise(&released); // attach key pressed function
k = 0;
- doRun = true;
+ doRun = false;
// pt1.reset(0.0f);
- dist = 0;
- strength = 0;
+ dist = 0.0f;
+ strength = 0.0f;
dt = 0.0f;
twhile.start();
}
@@ -52,34 +49,25 @@
float dt = twhile.read();
twhile.reset();
- k++;
dist = tfmini();
strength = tfmini.readStrength();
if(doRun) {
- pc.printf("%i %f %i %i \r\n", k, dt, dist, strength);
- // pc.printf("%i %i %i \r\n", k, dist, strength);
- receiveComplete = false;
+ pc.printf("%i %f %f %f \r\n", k, dt, dist, strength);
}
+ k++;
}
// buttonhandling
// -----------------------------------------------------------------------------
// start timer as soon as button is pressed
-void pressed()
-{
- t.start();
-}
+void pressed() {}
// evaluating statemachine
void released()
{
// toggle state over boolean
- if(doRun) {
- k = 0;
- }
doRun = !doRun;
- t.stop();
- t.reset();
+ k = 0;
}