safety critical
/
PwmOut_HelloWorld
lab5
Fork of PwmOut_HelloWorld by
main.cpp
- Committer:
- Asimtaj
- Date:
- 2017-11-23
- Revision:
- 4:ef9385dba098
- Parent:
- 1:5160ea45399b
File content as of revision 4:ef9385dba098:
#include "mbed.h" PwmOut PWM0(p21); //PWM out AnalogIn ain0(p16); //Analog input A0 AnalogIn ain1(p20); //Analog input A1 DigitalOut ledasim(LED1); DigitalOut ledasim2(LED2); Serial pc(USBTX, USBRX); // tx, rx float test=0; int main() { int ain11 = 0; //PWM0.period(0.0f); // 0second period //PWM0.write(0.0f); test=ain1; pc.printf("%f\n\r",test); wait(5); while(ain1>0.18){ test=ain1; pc.printf("%f\n\r",test); } while(1){ if(ain1<0.8){ // specify period first PWM0.period(0.0025f); // 0.0025 second period PWM0.write(0.8f); // 50% duty cycle, relative to period //led = 0.5f; // shorthand for led.write() //led.pulsewidth(2); // alternative to led.write, set duty cycle time in seconds //printf("ll"); ledasim=!ledasim; //printf("%f\n\r",ain0); //printf(" %f\n\r", ain0.read()); } wait(5); while(1){ wait(0.25); test=ain0; pc.printf("%f\n\r",test); if(ain0 > 0.289 || ain0 < 0.268) { PWM0.period(0.0f); // 0second period PWM0.write(0.0f); ain11= 1; } else if(ain11 == 0){ PWM0.period(0.0025f); // 0second period PWM0.write(0.8f); } } } }