« Back to documentation index 
    
PwmOut Class Reference 
A pulse-width modulation digital output.  
More... 
#include <PwmOut.h >
  PwmOut  (PinName pin)  Create a PwmOut  connected to the specified pin.   void  write  (float value)  Set the ouput duty-cycle, specified as a percentage (float)   float  read  ()  Return the current output duty-cycle setting, measured as a percentage (float)   void  period  (float seconds)  Set the PWM period, specified in seconds (float), keeping the duty cycle the same.   void  period_ms  (int ms)  Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same.   void  period_us  (int us)  Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same.   void  pulsewidth  (float seconds)  Set the PWM pulsewidth, specified in seconds (float), keeping the period the same.   void  pulsewidth_ms  (int ms)  Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same.   void  pulsewidth_us  (int us)  Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same.   PwmOut  & operator=  (float value)  A operator shorthand for write()    PwmOut  & operator=  (PwmOut  &rhs)  A operator shorthand for write()      operator float  ()  An operator shorthand for read()    void  lock_deep_sleep  ()  Lock deep sleep only if it is not yet locked.   void  unlock_deep_sleep  ()  Unlock deep sleep in case it is locked.   
Detailed Description 
A pulse-width modulation digital output. 
Note: Synchronization level: Interrupt safe Example 
 
 #include "mbed.h" 
 PwmOut  led(LED1);
 int  main() {
     while (1) {
         led = led + 0.01;
         wait (0.2);
         if (led == 1.0) {
             led = 0;
         }
     }
 }
 Definition at line 52  of file PwmOut.h .
Constructor & Destructor Documentation 
Create a PwmOut  connected to the specified pin. 
Parameters: 
  
   
Definition at line 60  of file PwmOut.h .
 
 
Member Function Documentation 
      
        
          void lock_deep_sleep  
          ( 
           ) 
           [protected] 
      
 
Lock deep sleep only if it is not yet locked. 
Definition at line 189  of file PwmOut.h .
 
 
      
        
          PwmOut & operator= ( 
          float  
           value  ) 
           
      
 
 
      
        
          void period  
          ( 
          float  
           seconds  ) 
           
      
 
Set the PWM period, specified in seconds (float), keeping the duty cycle the same. 
Parameters: 
  
    seconds Change the period of a PWM signal in seconds (float) without modifying the duty cycle  
   
Note: The resolution is currently in microseconds; periods smaller than this will be set to zero.  Definition at line 110  of file PwmOut.h .
 
 
      
        
          void period_ms  
          ( 
          int  
           ms  ) 
           
      
 
Set the PWM period, specified in milli-seconds (int), keeping the duty cycle the same. 
Parameters: 
  
    ms Change the period of a PWM signal in milli-seconds without modifying the duty cycle  
   
Definition at line 119  of file PwmOut.h .
 
 
      
        
          void period_us  
          ( 
          int  
           us  ) 
           
      
 
Set the PWM period, specified in micro-seconds (int), keeping the duty cycle the same. 
Parameters: 
  
    us Change the period of a PWM signal in micro-seconds without modifying the duty cycle  
   
Definition at line 128  of file PwmOut.h .
 
 
      
        
          void pulsewidth  
          ( 
          float  
           seconds  ) 
           
      
 
Set the PWM pulsewidth, specified in seconds (float), keeping the period the same. 
Parameters: 
  
    seconds Change the pulse width of a PWM signal specified in seconds (float)  
   
Definition at line 137  of file PwmOut.h .
 
 
      
        
          void pulsewidth_ms  
          ( 
          int  
           ms  ) 
           
      
 
Set the PWM pulsewidth, specified in milli-seconds (int), keeping the period the same. 
Parameters: 
  
    ms Change the pulse width of a PWM signal specified in milli-seconds  
   
Definition at line 146  of file PwmOut.h .
 
 
      
        
          void pulsewidth_us  
          ( 
          int  
           us  ) 
           
      
 
Set the PWM pulsewidth, specified in micro-seconds (int), keeping the period the same. 
Parameters: 
  
    us Change the pulse width of a PWM signal specified in micro-seconds  
   
Definition at line 155  of file PwmOut.h .
 
 
Return the current output duty-cycle setting, measured as a percentage (float) 
Returns: A floating-point value representing the current duty-cycle being output on the pin, measured as a percentage. The returned value will lie between 0.0f (representing on 0%) and 1.0f (representing on 100%). Note: This value may not match exactly the value set by a previous write() .  Definition at line 96  of file PwmOut.h .
 
 
      
        
          void unlock_deep_sleep  
          ( 
           ) 
           [protected] 
      
 
Unlock deep sleep in case it is locked. 
Definition at line 197  of file PwmOut.h .
 
 
      
        
          void write  
          ( 
          float  
           value  ) 
           
      
 
Set the ouput duty-cycle, specified as a percentage (float) 
Parameters: 
  
    value A floating-point value representing the output duty-cycle, specified as a percentage. The value should lie between 0.0f (representing on 0%) and 1.0f (representing on 100%). Values outside this range will be saturated to 0.0f or 1.0f.  
   
Definition at line 79  of file PwmOut.h .