Atope
/
PRACTICA3
ccvcv
Fork of PRACTICA3 by
main.cpp
- Committer:
- jon07
- Date:
- 2017-11-13
- Revision:
- 5:18feff1607c9
- Parent:
- 4:71a955ddc240
File content as of revision 5:18feff1607c9:
#include "mbed.h" #define period 1/5000 #define sizeVector 100 #define Constant (0.000001661707484) //USER_BUTTON o PC_13 InterruptIn button(PC_13); uint32_t vA[sizeVector]; uint32_t vB[sizeVector]; AnalogIn valors(A0); int counter=0; int flag=0; int whatVector=0; uint64_t sum_values=0; float RMS_value=0; float Vpp_value=0; float Max_value=0; float Min_value=1000; int state=0; Ticker sample; Ticker visualize; void fsample() //?? { if (whatVector) { vB[counter]=(valors.read_u16()+valors.read_u16()+valors.read_u16()+valors.read_u16())/4; } else { vA[counter]=(valors.read_u16()+valors.read_u16()+valors.read_u16()+valors.read_u16())/4; } counter++; if (counter==100) { counter=1; flag=1; whatVector=!whatVector; //?? } } void change() //?? { state=!state; } void visualiza() { if(state){ printf("RMS value is =%f",RMS_value); } else { printf("Vpp value is =%f",Vpp_value); } } int main() { uint32_t temp; sample.attach(&fsample,period); //& para llamar a la función visualize.attach(&visualiza,1); button.rise(&change); while(1) { if (flag) { flag=0; sum_values=0; if(whatVector) { for(int n=0; n<99; n++) { temp=vA[n]; sum_values=sum_values+temp; if(Max_value<temp) { Max_value=temp; } if(Min_value>temp) { Min_value=temp; } } } else { for(int n=0; n<99; n++) { temp=vB[n]; sum_values=sum_values+temp; if(Max_value<temp) { Max_value=temp; } if(Min_value>temp) { Min_value=temp; } } } RMS_value=sqrt(Constant*(float)sum_values); Vpp_value=Max_value-Min_value; } } }