Accelerometer simulator

Dependencies:   mbed

Revision:
1:a31564d0b86c
Parent:
0:8ef83d7dc88d
Child:
2:fbb699c3994f
--- a/main.cpp	Mon Oct 12 15:24:01 2020 +0000
+++ b/main.cpp	Tue Oct 20 14:40:30 2020 +0000
@@ -1,31 +1,31 @@
 #include "mbed.h"
 
 Serial pc(PA_2,PA_3,115200);
-char data;
-int dato1 = 12345;
-float dato2 = 1.2345e-21;
+DigitalIn myBtn(PC_13);
+Timer timer;
+// Clock frequency 84MHz 12ns Instruction clock
+unsigned int nSamples,cnt;
+float sampPer,elapTime;
 
-int main(){
-    pc.printf("Hello world!!!\r\n");
-    pc.putc('T');
-    pc.putc('h');
-    pc.putc('i');
-    pc.putc('s');
-    pc.putc(' ');
-    pc.putc('i');
-    pc.putc('s');
-    pc.putc(' ');
-    pc.putc('p');
-    pc.putc('u');
-    pc.putc('t');
-    pc.putc('c');
-    pc.putc('\r');
-    pc.putc('\n');
-    pc.printf("The first value is %d and the second value is %e\r\n",dato1,dato2);
-    while(1){
-        data=pc.getc();  
-        pc.putc(data);  
-        if(data=='\r')
-            pc.putc('\n');    
-    }    
+int main()
+{
+    pc.printf("Press the user button to start\r\n");
+    while(myBtn);
+    while(!myBtn);
+    pc.printf("Good Job!!!\r\n");
+    timer.start();
+        while(1) {
+        pc.printf("How many samples do you desire? ");
+        pc.scanf("%u",&nSamples);
+        pc.printf("\r\nEntered %d.\r\n",nSamples);
+        pc.printf("Please, provide the sampling period [s] ");
+        pc.scanf("%f",&sampPer);
+        pc.printf("\r\nEntered %f.\r\n",sampPer);
+        for(cnt=0; cnt<nSamples; cnt++) {
+            timer.reset();
+            pc.printf("Value: %u\r\n",cnt);
+            elapTime = timer.read();
+            wait(sampPer - elapTime);
+        }
+    }
 }
\ No newline at end of file