ES305H Lanier Turchan / Mbed 2 deprecated Turret_Angle

Dependencies:   QEI mbed

Turret_Angle_encoder.cpp

Committer:
LanierUSNA16
Date:
2015-03-12
Revision:
1:ec3cdf28c947
Parent:
0:60646c7af7a9
Child:
2:53a4071435ba
Child:
3:caefffcb7141

File content as of revision 1:ec3cdf28c947:

#include "mbed.h"
#include "QEI.h"

QEI myEncoder (p16,p15, NC, 1600); 
Timer t;


int main ()
{
    int counter = 0;
    float time[500] ; 
    float theta[500] ; 
    int pulses = 0; 
    int k = 0; 
    t.start();

    wait (1);
    
    while (time[counter]<5.05)
    {
        wait(0.01); 
        pulses = myEncoder.getPulses(); 
        theta[counter] = ((float)pulses/ (1600.0*2.0))*2.0*3.14;
        time[counter] = t.read(); 
        printf("Time(%d)= %f       Angle(%d) = %f \n", counter+1,time[counter],counter+1, theta[counter]);
        counter= counter + 1; 
    }
    t.stop();
    printf("Printing log variables to file on mBed           ... ");
    
    LocalFileSystem local("local");
    FILE *fp = fopen("/local/turret_angle.M", "w");

    if(1) 
    {
        for(k=0; k<501; k++) 
        {
            fprintf(fp,"time(%d,1) = %.5f;\n",k+1,time[k]);
            fprintf(fp,"theta(%d,1) = %.5f;\n",k+1,theta[k]);  
            printf("In the loop");          
        }        
    }
    fclose(fp); 
    printf("Done printing\n"); 
}