Important changes to repositories hosted on mbed.com
Mbed hosted mercurial repositories are deprecated and are due to be permanently deleted in July 2026.
To keep a copy of this software download the repository Zip archive or clone locally using Mercurial.
It is also possible to export all your personal repositories from the account settings page.
PwmOut.h
00001 #ifndef CPP_TO_PIGPIO_PWMOUT_HEADER 00002 #define CPP_TO_PIGPIO_PWMOUT_HEADER 00003 namespace CPPToPigpio{ 00004 00005 /** The PwmOut interface is used to control the frequency and mark-space ratio of a digital pulse train. 00006 */ 00007 class PwmOut : public CPPToPigpio{ 00008 private: 00009 PinName _pin; 00010 float _pwmValue; //Is a percentage that duty cycle is high (0-1) 00011 00012 public: 00013 00014 /** Create a PwmOut connected to the specified pin 00015 * 00016 * @param pin PwmOut pin to connect to 00017 */ 00018 PwmOut(PinName pin); 00019 00020 /** Create a PwmOut connected to the specified pin 00021 * 00022 * @param pin PwmOut pin to connect to 00023 * @param value A floating-point value representing the output duty-cycle, 00024 * specified as a percentage. The value should lie between 00025 * 0.0f (representing on 0%) and 1.0f (representing on 100%). 00026 * Values outside this range will be saturated to 0.0f or 1.0f. 00027 */ 00028 PwmOut(PinName pin, float val); //actually doesn't exist in standard mbed, but makes it easier 00029 00030 /** Create a PwmOut connected to the specified pin 00031 * 00032 * @param pin PwmOut pin to connect to 00033 */ 00034 PwmOut(int pin); 00035 00036 /** Create a PwmOut connected to the specified pin 00037 * 00038 * @param pin PwmOut pin to connect to 00039 * @param value A floating-point value representing the output duty-cycle, 00040 * specified as a percentage. The value should lie between 00041 * 0.0f (representing on 0%) and 1.0f (representing on 100%). 00042 * Values outside this range will be saturated to 0.0f or 1.0f. 00043 */ 00044 PwmOut(int pin, float val); 00045 00046 /** Set the ouput duty-cycle, specified as a percentage (float) 00047 * 00048 * @param value A floating-point value representing the output duty-cycle, 00049 * specified as a percentage. The value should lie between 00050 * 0.0f (representing on 0%) and 1.0f (representing on 100%). 00051 * Values outside this range will be saturated to 0.0f or 1.0f. 00052 */ 00053 void write(float val); 00054 00055 /** Return the current output duty-cycle setting, measured as a percentage (float) 00056 * 00057 * @returns 00058 * A floating-point value representing the current duty-cycle being output on the pin, 00059 * measured as a percentage. The returned value will lie between 00060 * 0.0f (representing on 0%) and 1.0f (representing on 100%). 00061 * 00062 */ 00063 float read(); //Returns current output duty cycle 00064 00065 /** Set the PWM period, specified in seconds (float), keeping the duty cycle the same. 00066 * 00067 * @param seconds Change the period of a PWM signal in seconds (float) without modifying the duty cycle 00068 * 00069 */ 00070 float period(float seconds); //set PWM period, returns a float matching period that the device was actually set to 00071 00072 /** Set the PWM period, specified in miliseconds (int), keeping the duty cycle the same. 00073 * 00074 * @param miliseconds Change the period of a PWM signal in miliseconds (int) without modifying the duty cycle 00075 * 00076 */ 00077 float period_ms(int ms); 00078 00079 /** Set the PWM period, specified in microseconds (int), keeping the duty cycle the same. 00080 * 00081 * @param microseconds Change the period of a PWM signal in microseconds (int) without modifying the duty cycle 00082 * 00083 */ 00084 float period_us(int us); 00085 00086 /** A operator shorthand for write() 00087 * \sa PwmOut::write() 00088 */ 00089 PwmOut & operator=(float val); 00090 00091 /** A operator shorthand for write() 00092 * \sa PwmOut::write() 00093 */ 00094 PwmOut & operator=(PwmOut &); 00095 00096 /** An operator shorthand for read() 00097 * \sa PwmOut::read() 00098 */ 00099 operator float(); 00100 00101 /** Deconstructor 00102 */ 00103 ~PwmOut(); 00104 }; 00105 00106 } 00107 #endif
Generated on Tue Jul 12 2022 14:39:23 by
1.7.2