This example demonstrates how to use the EMG signal to set two control commands. The program works as follows: if the muscle is tensioned for 1 second or less, the program will display the value "Type 1", if more than a second, then the value "Type 2". This program can be used as the easiest way to control a robotic arm, motor or just an LED. For example: if we stretch the arm for less than 1 s, then the robotic arm will make a fist-type grip, if for more than 1 s, then the robotic arm will make a pinch grip. In the case of the LED: when the hand voltage is short, the LED will blink 1 time, in case of continuous hand voltage, the LED will blink twice.
The program constantly monitors the magnitude of the amplitude of the recorded signal. As soon as the amplitude value exceeds a certain threshold thresholdStart, the program understands that the muscle is tense and starts counting the time (EMG_TimeStart). As soon as the amplitude of the EMG signal becomes less than the threshold value thresholdEnd, the program detects that the muscle is no longer strained and calculates the time interval EMG_Time, during which the EMG was recorded. Depending on the value of EMG_Time, the value "Type 1" or "Type 1" is displayed.
For the program to work correctly, it is important to set the thresholdStart and thresholdEnd parameters that are individual for each user. To do this, first run the "Terminal" example above and display the EMG signal. thresholdStart set as half the value of the maximum amplitude, thresholdEnd as the doubled value of the interference value in the absence of an EMG signal. If the recorded EMG signal turns out to be small in amplitude, it sets the increasing gain using the MyoSensor.gain (value) function, where one of the following gain values is used as the argument "value": "x1", "x2", "x4", "X5", "x8", "x10", "x16", "x32".