Oleksandr Malyuskin / Mbed 2 deprecated Nucleo_pwm1

Dependencies:   mbed

main.cpp

Committer:
malyuskin
Date:
2019-11-07
Revision:
0:370b9123668e

File content as of revision 0:370b9123668e:



#include "mbed.h"
PwmOut ledpwm(A6);
DigitalIn din(D6) ;
AnalogIn analog_value(A0);


int main() {
    float meas_r = 0 ;
   
    while(1) {
       
      if(din.read()==0){  //switch is OFF
      
      ledpwm.period_ms(10);  // PWM period is 10ms
     
      ledpwm.write(0);       // 0% duty cycle, LED is OFF    
           
      }
     
     else if(din.read()==1){  //switch is ON
     
     ledpwm.period_ms(10);  // PWM period is 10ms
     
     ledpwm.write(0.5);     // 100% duty cycle, LED is fully ON
         
     wait(0.3);  
       
    // controlling LED brightness by varying potentiometer reading
          
     meas_r = analog_value.read();
   
     if (meas_r>0.2){ledpwm.write(meas_r);}  //this is done to make sure that 
     // the LED does not go OFF completely, if potentiometer is "switched OFF"
          
     else   ledpwm.write(0.2);
    
     wait(0.5);  
  
   }
      
   
   }
     
            
   
}