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 sagawa_lpc1114 by
SoftPWM.h
00001 #ifndef SoftPWM_H 00002 #define SoftPWM_H 00003 #define POSITIVE true 00004 #define NEGATIVE false 00005 00006 #include "mbed.h" 00007 00008 class SoftPWM 00009 { 00010 private: 00011 Timeout _timeout; 00012 Ticker _ticker; 00013 void end(); 00014 DigitalOut pulse; 00015 bool positive; 00016 void TickerInterrapt(); 00017 float width; 00018 float interval; 00019 public: 00020 SoftPWM(PinName,bool mode=true); 00021 // void attach_us(int); 00022 void start(); 00023 void write(float); 00024 float read(); 00025 void pulsewidth(float); 00026 void pulsewidth_ms(int); 00027 void pulsewidth_us(int); 00028 void period(float); 00029 void period_ms(int); 00030 void period_us(int); 00031 void stop(); 00032 operator float() { 00033 if ( width <= 0.0 ) return 0.0; 00034 if ( width > 1.0 ) return 1.0; 00035 return width / interval; 00036 } 00037 SoftPWM& operator=(float duty) { 00038 width = interval * duty; 00039 if ( duty <= 0.0 ) width = 0.0; 00040 if ( duty > 1.0 ) width = interval; 00041 return *this; 00042 } 00043 00044 }; 00045 #endif
Generated on Sat Aug 6 2022 18:01:58 by
1.7.2
