Reply To: EMS Example

Recent Topics Forums Development EMS Example Reply To: EMS Example

#312
H2L
Keymaster

    @tak22

    Thank you for your question. When you wish to move the hands,
    wrist or fingers of the wearer, a few things need to be done with the code.

    – Initialize EMS
    – Configure EMS parameters (intensity and duration)
    – Pick the electrode you wish to deliver EMS with.
    – Update EMS

    The following sample shows how a single instance of EMS can be
    configured and then delivered upon the insertion of a serial command.

    You will need to. . .
    SET EMS PARAMETERS and PICK ELECTRODE TO DELIVER EMS.
    after that. . .
    compile the code, bring up the serial monitor and insert ‘d’
    to activate the stimulation.

    
    #include <UH.h>
    UH uh;  // create an UH object
    
    int inByte = 0;
    int voltage;
    int channel;
    
    void setup(){
      // initialize serial communication:
      Serial.begin(115200);
      
      // initialize EMS
      uh.initEMS(); 
    
      // SET EMS PARAMETERS
      voltage = 8;               // min: 0  max: 12
      uh.stimuTimeCount = 650;   // min: 0  max: 650
    
      // PICK ELECTRODE TO DELIVER EMS
      channel = 0; 
        // channel 0: Contracts Hand
        // channel 1: Pulls in Fingers (Index/Middle/Ring)
        // channel 2: Pulls in Fingers (Middle/Ring/Pinky)
        // channel 3: Pulls in Fingers (Ring/Pinky)
        // channel 4: Releases Hand
        // channel 5: extends Index Finger
        // channel 6: Tingle on forearm
        // channel 7: Pulls in Fingers (Index/Middle)
    
    }
    
    void loop(){  
      // update EMS  
      uh.updateEMS();
    }
    
    void serialEvent() {
      if(Serial.available()>0){
        inByte = Serial.read();
        if (inByte == 100 || inByte == 68){ // when 'd' is inputted. . .
    
          // countdown
             Serial.print("3...");
             delay (1000);
             Serial.print("2...");
             delay (1000);
             Serial.print("1...");
             delay (1000);
    
          // deliver stimulation
             uh.setStimulationChannel(channel);
             uh.setStimulationTime();
             uh.setStimulationVoltage(voltage);
             for(int i=0;i<50;i++){uh.keepVoltage(voltage);} 
             Serial.print("\nstimulate!\n\n");
        }
      }
    }
    
    • This reply was modified 7 years, 9 months ago by H2L.