MyoWare Sensor / MyoWare
Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers MyoWare.h Source File

MyoWare.h

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 #ifndef MyoWare_Mbed_H
00013 #define MyoWare_Mbed_H
00014 
00015 #include "mbed.h"
00016 
00017 /** MyoWare Muscle Sensor
00018  *
00019  *  Example:
00020  *  @code
00021  *  #include "mbed.h"
00022  *#include "MyoWare.h"
00023  *
00024  *Serial pc(USBTX, USBRX); // tx, rx
00025  *
00026  *float logic = 0.7f; 
00027  *int steps = 20;
00028  *MyoWare ms(p15, logic, steps);
00029  *
00030  *int main() {
00031  *  
00032  *  while(1) {
00033  *      float sig_val = ms.read();
00034  *      bool onOff = ms.control();
00035  *      int stepNum = ms.magnitude();
00036  *      pc.printf("Sig Value: %f\n\r", sig_val);  
00037  *      pc.printf("Logic Value: %f\n\r", logic);  
00038  *      pc.printf("Digital Value: %d\n\r", onOff); 
00039  *      pc.printf("Total Steps: %d\n\r", steps);
00040  *      pc.printf("Step Value Value: %d\n\r", stepNum); 
00041  *      pc.printf("\n\r"); 
00042  *      wait(2);
00043  *  }
00044  *  
00045  *}
00046  *  @endcode
00047  */
00048  
00049 class MyoWare {
00050     
00051 public:
00052     
00053     MyoWare(PinName pin); //Setup myoware sensor signal pin.
00054     
00055     MyoWare(PinName pin, float _level); //Initialize with logic level.
00056     // Initializes the sensor API to be used as a digital out through the
00057     // control() function.
00058     
00059     MyoWare(PinName pin, float _level, int _grad); 
00060     //Initialize as digital out.
00061     //Includes the gradient functionality for integer steps input.
00062     
00063     float read(); //Read the input value of the myoware sensor.
00064     
00065     bool control();
00066     // Returns 1 if output signal value is greater than level supplied.
00067     // Otherwise returns 0.
00068     
00069     int magnitude();
00070     // Accepts a step count number, and returns the value of the step which 
00071     // the value currently resides.
00072     // EX. if the step count is 10, then gradient will return the interger of
00073     // the number of time the signal value is divisible by .1.
00074     
00075     operator float();
00076     
00077 protected:
00078     AnalogIn _analog; //Input from myoware is analog in.
00079     float _val; //Variable for saving a single read value from the myoware.
00080     float _level; //Variable for setting the input logic level control.
00081     float _logic; //Single read value of the _level control.
00082     int _grad; //Input variable for the number of gradient steps.
00083     float _sections; //Value for containing the current value of each section.
00084 
00085 };
00086 
00087 #endif