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.
MyoWare.cpp
00001 /** MyoWare Muscle Sensor control API 00002 * 00003 * @class MyoWare_Muscle_Sensor 00004 * @author Jake Ashmore, Chris Turner 00005 * @version 1.0b (March 7, 2017) 00006 * 00007 * 00008 * ----------------------IMPORTANT-------------------- 00009 * --------------------------------------------------- 00010 */ 00011 00012 #include "MyoWare.h" 00013 #include "mbed.h" 00014 00015 bool digOut(float _val, float _logic) { 00016 if (_val > _logic) { 00017 return 1; 00018 } else { 00019 return 0; 00020 } 00021 } 00022 00023 MyoWare::MyoWare(PinName pin) :_analog(pin) 00024 { 00025 _val = _analog; 00026 } 00027 00028 MyoWare::MyoWare(PinName pin, float _level) :_analog(pin) 00029 { 00030 _val = _analog; 00031 00032 if ( _level > 0.0f ) { 00033 _logic = _level; 00034 } else { 00035 _logic = 0.0f; 00036 } 00037 } 00038 00039 MyoWare::MyoWare(PinName pin, float _level, int _grad) :_analog(pin) 00040 { 00041 _val = _analog; 00042 00043 if ( _level > 0.0f ) { 00044 _logic = _level; 00045 } else { 00046 _logic = 0.0f; 00047 } 00048 00049 if ( _grad > 0) { 00050 _sections = float((100/_grad)/100.0f); 00051 } else { 00052 _sections = 1.0f; 00053 } 00054 00055 } 00056 00057 float MyoWare::read() { 00058 return _val = _analog; 00059 } 00060 00061 MyoWare::operator float() { 00062 return read(); 00063 } 00064 00065 bool MyoWare::control() { 00066 if ( _logic == 0.0f ) { 00067 return 0; 00068 } else { 00069 return digOut(_val, _logic); 00070 } 00071 } 00072 00073 int MyoWare::magnitude() { 00074 int temp; 00075 if ( (_sections == 1.0f ) && (_val > 0.0f )) { 00076 temp = 1; 00077 } else if ( (_sections > 0.0f ) && (_val > 0.0f ) ) { 00078 temp = int(floor(_val/_sections)); 00079 } else { 00080 temp = 0; 00081 } 00082 return temp; 00083 }
Generated on Sun Jul 17 2022 10:00:36 by
1.7.2