Accelerometer simulator

Dependencies:   mbed

Committer:
rschiano
Date:
Tue Oct 20 14:40:30 2020 +0000
Revision:
1:a31564d0b86c
Parent:
0:8ef83d7dc88d
Child:
2:fbb699c3994f
Data acquisition simulator. Data are sent via virtual COM port

Who changed what in which revision?

UserRevisionLine numberNew contents of line
rschiano 0:8ef83d7dc88d 1 #include "mbed.h"
rschiano 0:8ef83d7dc88d 2
rschiano 0:8ef83d7dc88d 3 Serial pc(PA_2,PA_3,115200);
rschiano 1:a31564d0b86c 4 DigitalIn myBtn(PC_13);
rschiano 1:a31564d0b86c 5 Timer timer;
rschiano 1:a31564d0b86c 6 // Clock frequency 84MHz 12ns Instruction clock
rschiano 1:a31564d0b86c 7 unsigned int nSamples,cnt;
rschiano 1:a31564d0b86c 8 float sampPer,elapTime;
rschiano 0:8ef83d7dc88d 9
rschiano 1:a31564d0b86c 10 int main()
rschiano 1:a31564d0b86c 11 {
rschiano 1:a31564d0b86c 12 pc.printf("Press the user button to start\r\n");
rschiano 1:a31564d0b86c 13 while(myBtn);
rschiano 1:a31564d0b86c 14 while(!myBtn);
rschiano 1:a31564d0b86c 15 pc.printf("Good Job!!!\r\n");
rschiano 1:a31564d0b86c 16 timer.start();
rschiano 1:a31564d0b86c 17 while(1) {
rschiano 1:a31564d0b86c 18 pc.printf("How many samples do you desire? ");
rschiano 1:a31564d0b86c 19 pc.scanf("%u",&nSamples);
rschiano 1:a31564d0b86c 20 pc.printf("\r\nEntered %d.\r\n",nSamples);
rschiano 1:a31564d0b86c 21 pc.printf("Please, provide the sampling period [s] ");
rschiano 1:a31564d0b86c 22 pc.scanf("%f",&sampPer);
rschiano 1:a31564d0b86c 23 pc.printf("\r\nEntered %f.\r\n",sampPer);
rschiano 1:a31564d0b86c 24 for(cnt=0; cnt<nSamples; cnt++) {
rschiano 1:a31564d0b86c 25 timer.reset();
rschiano 1:a31564d0b86c 26 pc.printf("Value: %u\r\n",cnt);
rschiano 1:a31564d0b86c 27 elapTime = timer.read();
rschiano 1:a31564d0b86c 28 wait(sampPer - elapTime);
rschiano 1:a31564d0b86c 29 }
rschiano 1:a31564d0b86c 30 }
rschiano 0:8ef83d7dc88d 31 }