ELCT-302 / Mbed 2 deprecated mbed_blinkyELCT302

Dependencies:   mbed

main.cpp

Committer:
jtho1327
Date:
2020-01-29
Revision:
26:abb0cc9a1dd2
Parent:
25:371af8d95c69

File content as of revision 26:abb0cc9a1dd2:

#include "mbed.h"
#include <iostream>
AnalogIn pot(PTB0);
PwmOut servo(PTE20);

int main() 
{
    double val = 0;
    int count = 0;
    servo.period(0.02);
    while(1) 
    {
        val = 0;
        for(int i=0; i<200; i++){
            wait(0.0001);
            val =  val + pot.read();
        }
        servo.pulsewidth(0.001+(val/200000));
       count = count +1; 
       if(count == 10){
        cout << "period: " <<((0.001+ val/200000)/0.02)*100 << "%" <<endl;
        count = 0;
        }
        
    }
}