Yeongsoo Kim / Mbed 2 deprecated Mecha_Distance_Sensor

Dependencies:   mbed

main.cpp

Committer:
yeongsookim
Date:
2020-11-11
Revision:
0:64fe0ebc42c6

File content as of revision 0:64fe0ebc42c6:

#include "mbed.h"
#include "DistanceSensor.h"
#include "Plotting.h"

//To plot with usb, set as below.
Serial pc(USBTX,USBRX); // Tx, Rx Pin
Plotting plot;

//Set each gpio to see the output of the psd sensor as a led
DistanceSensor pir (p20);

//Interrupt is generated every 1ms and degree is increased by 1
unsigned int uiFlag_50ms = 0;
    
void counter_1ms ()
{
    uiFlag_50ms++;
}

// Plot distance sensor
int main()
{
    wait(1);

    //Set the 1ms thicker.
    Ticker ticker_1ms;
    ticker_1ms.attach(&counter_1ms,0.001);

    Timer time;
    time.start();

    while(1) {
        // Every 50 ms,
        if(uiFlag_50ms>=50) {
            uiFlag_50ms=0;
            
            // clear plotting buffer
            plot.reset();
            
            // put data to buffer
            plot.put(pir.getDistance_cm(),0);
            
            // send buffer
            plot.send(&pc);
        }
    }
}