lab2_4
Dependencies: mbed 2_4_PWM_Ouput
main.cpp
- Committer:
- shih775007
- Date:
- 2017-03-01
- Revision:
- 1:4340a1ec8b5c
- Parent:
- 0:543a9d21e043
File content as of revision 1:4340a1ec8b5c:
#include "mbed.h" PwmOut PWM1(D6); Serial pc( USBTX, USBRX ); AnalogIn Ain(A0); float ADCdata; int main() { int on = 0; int off = 0; float Cycle = 0.0; PWM1.period(0.5); PWM1 = 0.5; while(1){ ADCdata = Ain; if(ADCdata > 0.5){ on = on + 1; } else{ off = off + 1.0; } Cycle = float(on)/(float(off)+float(on)); pc.printf("%f\r\n", Cycle); //pc.printf("%1.3f\r\n", off); wait(0.1); } }