first release. It is in the process of creation. Library for Motorfader https://www.switch-science.com/catalog/1285/
Revision 0:6b9fc326f973, committed 2019-07-29
- Comitter:
- abanum
- Date:
- Mon Jul 29 05:42:03 2019 +0000
- Commit message:
- first release.; It is in the process of creation.
Changed in this revision
| Motorfader.cpp | Show annotated file Show diff for this revision Revisions of this file |
| Motorfader.h | Show annotated file Show diff for this revision Revisions of this file |
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Motorfader.cpp Mon Jul 29 05:42:03 2019 +0000
@@ -0,0 +1,75 @@
+/* mbed Motorfader Library
+ *
+ * Copyright (c) 2007-2010 sford, cstyles
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#include "Motorfader.h"
+#include "mbed.h"
+
+Motorfader::Motorfader(PinName anarogpin,PinName cwpin,PinName ccwpin) : _faderPos(anarogpin) ,_cwpwm(cwpin),_ccwpwm(ccwpin) {
+ _cwpwm.period(0.020);
+ _ccwpwm.period(0.020);
+ _cwpwm.write(1.0);
+ _ccwpwm.write(1.0);
+ _setPos = 0.0;
+ _setVel = 1.0;
+ wait_ms(10);
+}
+
+void Motorfader::set(float pos,float vel ) {
+ _setPos = pos;
+ _setVel = vel;
+ wait_ms(10);
+}
+
+float Motorfader::get() {
+ return _faderPos.read();
+}
+
+void Motorfader::update() {
+float P,D = 0;
+ _nowPos = _faderPos.read();
+ _cwpwm.write(0.0);
+ _ccwpwm.write(0.0);
+
+ P = abs(_setPos - _nowPos)*4.0f;
+ if (P >1.0f )
+ {
+ P =1.0f;
+// _oldPos = _nowPos;
+ }
+// D = -abs(_oldPos - _nowPos)*1.0f;
+// _oldPos = _nowPos;
+ if((_nowPos+0.03f) < _setPos)
+ {
+ _cwpwm.write(_setVel*(P+D));
+ _ccwpwm.write(0.0f);
+// printf("inc ");
+ }
+ if((_nowPos-0.03f) > _setPos)
+ {
+ _cwpwm.write(0.0f);
+ _ccwpwm.write(_setVel*(P+D));
+// printf("dec ");
+ }
+// printf("nowpos=%1.3f setpos==%1.3f\r\n",_nowPos,_setPos);
+
+}
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/Motorfader.h Mon Jul 29 05:42:03 2019 +0000
@@ -0,0 +1,81 @@
+/* mbed Motorfader Library
+ * Copyright (c) 2019 abanum
+ *
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
+ * of this software and associated documentation files (the "Software"), to deal
+ * in the Software without restriction, including without limitation the rights
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
+ * copies of the Software, and to permit persons to whom the Software is
+ * furnished to do so, subject to the following conditions:
+ *
+ * The above copyright notice and this permission notice shall be included in
+ * all copies or substantial portions of the Software.
+ *
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
+ * THE SOFTWARE.
+ */
+
+#ifndef MBED_Motorfader_H
+#define MBED_Motorfader_H
+
+#include "mbed.h"
+
+/** Motorfader control class, based on a PwmOut
+ *
+ * Example:
+ * @code
+ * // Continuously sweep the servo through it's full range
+ * #include "mbed.h"
+ * #include "WT20003M03.h"
+ *
+ * WT20003M03 myaudio(p21);
+ *
+ * int main() {
+ mysound.volume(8);
+ * while(1) {
+ * myaudio.play();
+ * wait(10);
+ * }
+ * }
+ * @endcode
+ */
+class Motorfader {
+
+public:
+ /** Create a servo object connected to the specified PwmOut pin
+ *
+ * @param pin DigitalOut pin to connect to
+ */
+ Motorfader(PinName analogpin,PinName cwpin,PinName ccwpin);
+
+ /** Set position
+ *
+ * @param addres
+ */
+ void set(float pos,float vel);
+
+ /** Get position
+ *
+ * @param Read volume.
+ */
+ float get();
+
+ void update();
+
+protected:
+ AnalogIn _faderPos;
+ PwmOut _cwpwm;
+ PwmOut _ccwpwm;
+ float _setPos;
+ float _setVel;
+ float _nowPos;
+ float _oldPos;
+// unsigned int _volume;
+};
+
+#endif
abanum abanum