Accelerometer simulator

Dependencies:   mbed

main.cpp

Committer:
rschiano
Date:
2020-10-20
Revision:
1:a31564d0b86c
Parent:
0:8ef83d7dc88d
Child:
2:fbb699c3994f

File content as of revision 1:a31564d0b86c:

#include "mbed.h"

Serial pc(PA_2,PA_3,115200);
DigitalIn myBtn(PC_13);
Timer timer;
// Clock frequency 84MHz 12ns Instruction clock
unsigned int nSamples,cnt;
float sampPer,elapTime;

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);
        }
    }
}