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.
Fork of command_AX12_petit_robot_v2 by
PwmOut.h
00001 /* mbed Microcontroller Library - PwmOut 00002 * Copyright (c) 2007-2011 ARM Limited. All rights reserved. 00003 */ 00004 00005 #ifndef MBED_PWMOUT_H 00006 #define MBED_PWMOUT_H 00007 00008 #include "device.h" 00009 00010 #if DEVICE_PWMOUT 00011 00012 #include "platform.h" 00013 #include "PinNames.h" 00014 #include "PeripheralNames.h" 00015 #include "Base.h" 00016 00017 namespace mbed { 00018 00019 /* Class: PwmOut 00020 * A pulse-width modulation digital output 00021 * 00022 * Example 00023 * > // Fade a led on. 00024 * > #include "mbed.h" 00025 * > 00026 * > PwmOut led(LED1); 00027 * > 00028 * > int main() { 00029 * > while(1) { 00030 * > led = led + 0.01; 00031 * > wait(0.2); 00032 * > if(led == 1.0) { 00033 * > led = 0; 00034 * > } 00035 * > } 00036 * > } 00037 * 00038 * Note that on the LPC1768 and LPC2368, the PWMs all share the same 00039 * period - if you change the period for one, you change it for all. 00040 * Although routines that change the period maintain the duty cycle 00041 * for its PWM, all other PWMs will require their duty cycle to be 00042 * refreshed. 00043 */ 00044 class PwmOut : public Base { 00045 00046 public: 00047 00048 /* Constructor: PwmOut 00049 * Create a PwmOut connected to the specified pin 00050 * 00051 * Variables: 00052 * pin - PwmOut pin to connect to 00053 */ 00054 PwmOut(PinName pin, const char *name = NULL); 00055 00056 /* Function: write 00057 * Set the ouput duty-cycle, specified as a percentage (float) 00058 * 00059 * Variables: 00060 * value - A floating-point value representing the output duty-cycle, 00061 * specified as a percentage. The value should lie between 00062 * 0.0f (representing on 0%) and 1.0f (representing on 100%). 00063 * Values outside this range will be saturated to 0.0f or 1.0f. 00064 */ 00065 void write(float value); 00066 00067 /* Function: read 00068 * Return the current output duty-cycle setting, measured as a percentage (float) 00069 * 00070 * Variables: 00071 * returns - A floating-point value representing the current duty-cycle being output on the pin, 00072 * measured as a percentage. The returned value will lie between 00073 * 0.0f (representing on 0%) and 1.0f (representing on 100%). 00074 * 00075 * Note: 00076 * This value may not match exactly the value set by a previous <write>. 00077 */ 00078 float read(); 00079 00080 /* Function: period 00081 * Set the PWM period, specified in seconds (float), keeping the 00082 * duty cycle the same. 00083 * 00084 * Note: 00085 * The resolution is currently in microseconds; periods smaller than this 00086 * will be set to zero. 00087 */ 00088 void period(float seconds); 00089 00090 /* Function: period_ms 00091 * Set the PWM period, specified in milli-seconds (int), keeping the 00092 * duty cycle the same. 00093 */ 00094 void period_ms(int ms); 00095 00096 /* Function: period_us 00097 * Set the PWM period, specified in micro-seconds (int), keeping the 00098 * duty cycle the same. 00099 */ 00100 void period_us(int us); 00101 00102 /* Function: pulsewidth 00103 * Set the PWM pulsewidth, specified in seconds (float), keeping the 00104 * period the same. 00105 */ 00106 void pulsewidth(float seconds); 00107 00108 /* Function: pulsewidth_ms 00109 * Set the PWM pulsewidth, specified in milli-seconds (int), keeping 00110 * the period the same. 00111 */ 00112 void pulsewidth_ms(int ms); 00113 00114 /* Function: pulsewidth_us 00115 * Set the PWM pulsewidth, specified in micro-seconds (int), keeping 00116 * the period the same. 00117 */ 00118 void pulsewidth_us(int us); 00119 00120 #ifdef MBED_OPERATORS 00121 /* Function: operator= 00122 * A operator shorthand for <write()> 00123 */ 00124 PwmOut& operator= (float value); 00125 PwmOut& operator= (PwmOut& rhs); 00126 00127 /* Function: operator float() 00128 * An operator shorthand for <read()> 00129 */ 00130 operator float(); 00131 #endif 00132 00133 #ifdef MBED_RPC 00134 virtual const struct rpc_method *get_rpc_methods(); 00135 static struct rpc_class *get_rpc_class(); 00136 #endif 00137 00138 protected: 00139 00140 PWMName _pwm; 00141 00142 }; 00143 00144 } // namespace mbed 00145 00146 #endif 00147 00148 #endif
Generated on Thu Jul 14 2022 20:44:47 by
