Frogolina
Published © MIT

LED clothes controlled via uMyo EMG sensor

I made LED clothes that are controlled by ESP32 and EMG signal from arm muscles.

IntermediateFull instructions provided12 hours293
LED clothes controlled via uMyo EMG sensor

Things used in this project

Software apps and online services

Addressable RGB ws2812 60 led/m black
ESP32
uMyo wearable EMG sensor with wet/dry electrodes

Story

Read more

Code

uMyo_light_clothing_vlib.ino

Arduino
#include <Arduino.h>

#include <uMyo_BLE.h>

#include <FastLED.h>

#define NUM_LEDS 162
#define DATA_PIN 13

int lamp_mode = 1;

typedef struct sPulses
{
  int pulse_count;
  float muscle_pulses[100];
  float travel_speed; //leds / second
  uint32_t last_pulse_time;
}sPulses;

CRGB leds[NUM_LEDS]; //1 + 33 + 33 + 47 + 47

int leds_intens = 10;
int leds_intens2 = 10;

void setup() {
  Serial.begin(115200);

  if(!lamp_mode) uMyo.begin();
  
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  // GRB ordering is assumed
  for(int x = 0; x < NUM_LEDS; x++)
    leds[x] = CRGB(5, 1, 2);
  FastLED.show();
  delay(500);  
}

void hsv2rgb(int h, float s, float v, float *r, float *g, float *b)
{
  v = v*0.01;
  s = s*0.01;
  if ( s == 0 ) //H 0...360, S, V from 0 to 1
  {
    *r = v * 255.0;
    *g = v * 255.0;
    *b = v * 255.0;
  }
  else
  {
    float var_h = (float)h / 60.0;
    if ( var_h >= 6.0 ) var_h = 5.99;      //H must be < 1
    int var_i = var_h;             //Or ... var_i = floor( var_h )
    float var_1 = v * ( 1.0 - s );
    float var_2 = v * ( 1.0 - s * ( var_h - var_i ) );
    float var_3 = v * ( 1.0 - s * ( 1.0 - ( var_h - var_i ) ) );

    float var_r, var_g, var_b;
    
    if      ( var_i == 0 ) { var_r = v     ; var_g = var_3 ; var_b = var_1; }
    else if ( var_i == 1 ) { var_r = var_2 ; var_g = v     ; var_b = var_1; }
    else if ( var_i == 2 ) { var_r = var_1 ; var_g = v     ; var_b = var_3; }
    else if ( var_i == 3 ) { var_r = var_1 ; var_g = var_2 ; var_b = v;     }
    else if ( var_i == 4 ) { var_r = var_3 ; var_g = var_1 ; var_b = v;     }
    else                   { var_r = v     ; var_g = var_1 ; var_b = var_2; }

    *r = var_r * 255.0;                  //RGB results from 0 to 255
    *g = var_g * 255.0;
    *b = var_b * 255.0;
  }
}

sPulses pulse1;
sPulses pulse2;
uint32_t prev_ms = 0;

void add_pulse(sPulses *pulses)
{
  if(pulses->pulse_count > 50) return;
  pulses->muscle_pulses[pulses->pulse_count] = 0;
  pulses->pulse_count++;
  pulses->last_pulse_time = millis();
}
void remove_pulse(int id, sPulses *pulses)
{
  if(id < 0) return;
  int moved = 0;
  for(int p = id; p < pulses->pulse_count; p++)
    pulses->muscle_pulses[p] = pulses->muscle_pulses[p+1], moved++;
  if(moved) pulses->pulse_count--;
}

void loop() {
  float pitch1 = 0, pitch2 = 0;
  if(!lamp_mode)
  {
    int dev_cnt = uMyo.getDeviceCount();
    if(dev_cnt > 0)
    {
      leds_intens = uMyo.getMuscleLevel(0);
      pitch1 = uMyo.getRoll(0);
    }
    if(dev_cnt > 1)
    {
      leds_intens2 = uMyo.getMuscleLevel(1);
      pitch2 = uMyo.getPitch(1);
    }
  }
  uint32_t ms = millis();
  int tm = ms%16000;
  float phase = tm - 8000;
  if(phase < 0) phase = -phase;
  phase /= 8000.0;
  for(int x = 1; x < NUM_LEDS; x++)
  {
    leds[x] = CRGB(0, 0, 0);
  }

  float dt = (ms - prev_ms) * 0.001;
  prev_ms = ms;
  for(int p = 0; p < pulse1.pulse_count; p++)
  {
    pulse1.muscle_pulses[p] += pulse1.travel_speed * dt;
    if(pulse1.muscle_pulses[p] > 55) remove_pulse(p, &pulse1);
  }
  for(int p = 0; p < pulse2.pulse_count; p++)
  {
    pulse2.muscle_pulses[p] += pulse2.travel_speed * dt;
    if(pulse2.muscle_pulses[p] > 55) remove_pulse(p, &pulse2);
  }

  float rel_led_intens = leds_intens - 50;
  float rel_led_intens2 = leds_intens2 - 50;
  if(rel_led_intens < 0) rel_led_intens = 0;
  if(rel_led_intens2 < 0) rel_led_intens2 = 0;
  rel_led_intens /= 400.0;
  rel_led_intens2 /= 400.0;
  rel_led_intens *= 3.0;
  rel_led_intens2 *= 3.0;
  if(rel_led_intens > 1) rel_led_intens = 1;
  if(rel_led_intens2 > 1) rel_led_intens2 = 1;
  pulse1.travel_speed = 45 + 30*rel_led_intens;
  pulse2.travel_speed = 45 + 30*rel_led_intens2;
  float freq = 5.0*rel_led_intens;
  float freq2 = 5.0*rel_led_intens2;
  int rr = rand()%100000;
  int rr2 = rand()%100000;
  float prob = dt * freq;
  float prob2 = dt * freq2;
//  if(rr < 100000.0*prob) add_pulse(&pulse1);
//  if(rr2 < 100000.0*prob2) add_pulse(&pulse2);
  int interval = 10000;
  int interval2 = 10000;
  if(rel_led_intens > 0.1)
      interval = 800 - 700*rel_led_intens;
  if(rel_led_intens2 > 0.1)
      interval2 = 800 - 700*rel_led_intens2;
  if(ms - pulse1.last_pulse_time > interval) add_pulse(&pulse1);
  if(ms - pulse2.last_pulse_time > interval2) add_pulse(&pulse2);

  int pulse_r = 0;//-55 + 30*rel_led_intens;
  int pulse_g = 60 + 40*rel_led_intens;
  int pulse_b = 60 + 40*rel_led_intens;
  pulse_r = pulse_g;
  int led_r = 10;
  int led_g = 0;//5 + phase*5;
  int led_b = 0;//15 - phase*5;
  if(pulse_r < 0) pulse_r = 0;
  if(pulse_r > 10) pulse_b -= (pulse_r - 10);
  for(int l = 0; l < 47; l++)
  {
    float min_dx = 100;
    for(int p = 0; p < pulse1.pulse_count; p++)
    {
      float dx = pulse1.muscle_pulses[p] - l;
      if(dx < 0) dx = -dx;
      if(dx < min_dx) min_dx = dx;
    }
    int lr = led_r, lg = led_g, lb = led_b;
    if(min_dx < 1) lr = pulse_r, lg = pulse_g, lb = pulse_b;
    leds[1+33*2+47-2-l] = CRGB(lr, lg, lb); 
    min_dx = 100;
    for(int p = 0; p < pulse2.pulse_count; p++)
    {
      float dx = pulse2.muscle_pulses[p] - l;
      if(dx < 0) dx = -dx;
      if(dx < min_dx) min_dx = dx;
    }
    lr = led_r, lg = led_g, lb = led_b;
    if(min_dx < 1) lr = pulse_r, lg = pulse_g, lb = pulse_b;
    
    leds[1+33*2+47-1+l] = CRGB(lr, lg, lb); 
  }
  static float alpha1 = 0, alpha2 = 0;
  float w1 = 5.0*pitch1;
  float w2 = 5.0*pitch2;
  alpha1 += dt*w1;
  alpha2 += dt*w2;
  if(alpha1 > 3.14159*2) alpha1 -= 3.14159*2;
  if(alpha2 > 3.14159*2) alpha2 -= 3.14159*2;
  for(int l = 0; l < 33; l++)
  {
    float angle = 0;
    if(l < 11) angle = 3.14159*0.667*0.091*l;
    else if(l < 22) angle = 3.14159*0.667 + 3.14159*0.667*0.091*(l-11);
    else angle = 3.14159*0.667*2 + 3.14159*0.667*0.091*(l-22);
    float da1 = alpha1 - angle;
    float da2 = alpha2 - angle;
    int h1 = da1/3.14159*180;
    int h2 = da2/3.14159*180;
    while(h1 < 0) h1 += 360;
    while(h2 < 0) h2 += 360;
    while(h1 > 360) h1 -= 360;
    while(h2 > 360) h2 -= 360;
    float r, g, b;
    int rr, gg, bb;
    hsv2rgb(h1, 100, 15, &r, &g, &b);
    rr = r; gg = g; bb = b;
    leds[1+l] = CRGB(rr, gg, bb);
    hsv2rgb(h2, 100, 15, &r, &g, &b);
    rr = r; gg = g; bb = b;
    leds[1+33+l] = CRGB(rr, gg, bb);
    
  }

  if(lamp_mode)
  { 
  int active_idx = phase * NUM_LEDS;
  for(int x = 0; x < NUM_LEDS; x++)
  {
    int h_idx = x * 360 / NUM_LEDS + phase * 360;
    h_idx = h_idx%360;
    float r, g, b;
    hsv2rgb(h_idx, 100, 20, &r, &g, &b);
    r *= 0.5;
    leds[x] = CRGB(r, g, b);
    int dx = x - active_idx;
    if(dx < 0) dx = -dx;
    if(dx == 0) leds[x] = CRGB(0, 15, 20);
    if(dx == 1) leds[x] = CRGB(0, 15, 15);
    if(dx == 2) leds[x] = CRGB(0, 13, 5);
  }
  }
  FastLED.show();
  Serial.println(leds_intens);
}

uMyo_light_clothing_v2.ino

C/C++
for second pattern
#include <Arduino.h>

#include <uMyo_BLE.h>

#include <FastLED.h>

#define NUM_LEDS 162
#define DATA_PIN 13

int lamp_mode = 0;

typedef struct sPulses
{
  int pulse_count;
  float muscle_pulses[100];
  float travel_speed; //leds / second
  uint32_t last_pulse_time;
}sPulses;

CRGB leds[NUM_LEDS]; //1 + 33 + 33 + 47 + 47

int leds_intens = 10;
int leds_intens2 = 10;

void setup() {
  Serial.begin(115200);

  if(!lamp_mode)
  {
    Serial.println("uMyo start");
    uMyo.begin();
  }
  
  FastLED.addLeds<NEOPIXEL, DATA_PIN>(leds, NUM_LEDS);  // GRB ordering is assumed
  for(int x = 0; x < NUM_LEDS; x++)
    leds[x] = CRGB(5, 1, 2);
  FastLED.show();
  delay(500);  
}

void hsv2rgb(int h, float s, float v, float *r, float *g, float *b)
{
  v = v*0.01;
  s = s*0.01;
  if ( s == 0 ) //H 0...360, S, V from 0 to 1
  {
    *r = v * 255.0;
    *g = v * 255.0;
    *b = v * 255.0;
  }
  else
  {
    float var_h = (float)h / 60.0;
    if ( var_h >= 6.0 ) var_h = 5.99;      //H must be < 1
    int var_i = var_h;             //Or ... var_i = floor( var_h )
    float var_1 = v * ( 1.0 - s );
    float var_2 = v * ( 1.0 - s * ( var_h - var_i ) );
    float var_3 = v * ( 1.0 - s * ( 1.0 - ( var_h - var_i ) ) );

    float var_r, var_g, var_b;
    
    if      ( var_i == 0 ) { var_r = v     ; var_g = var_3 ; var_b = var_1; }
    else if ( var_i == 1 ) { var_r = var_2 ; var_g = v     ; var_b = var_1; }
    else if ( var_i == 2 ) { var_r = var_1 ; var_g = v     ; var_b = var_3; }
    else if ( var_i == 3 ) { var_r = var_1 ; var_g = var_2 ; var_b = v;     }
    else if ( var_i == 4 ) { var_r = var_3 ; var_g = var_1 ; var_b = v;     }
    else                   { var_r = v     ; var_g = var_1 ; var_b = var_2; }

    *r = var_r * 255.0;                  //RGB results from 0 to 255
    *g = var_g * 255.0;
    *b = var_b * 255.0;
  }
}

sPulses pulse1;
sPulses pulse2;
uint32_t prev_ms = 0;

void add_pulse(sPulses *pulses)
{
  if(pulses->pulse_count > 50) return;
  pulses->muscle_pulses[pulses->pulse_count] = 0;
  pulses->pulse_count++;
  pulses->last_pulse_time = millis();
}
void remove_pulse(int id, sPulses *pulses)
{
  if(id < 0) return;
  int moved = 0;
  for(int p = id; p < pulses->pulse_count; p++)
    pulses->muscle_pulses[p] = pulses->muscle_pulses[p+1], moved++;
  if(moved) pulses->pulse_count--;
}

float roll1_spd = 0;
float roll2_spd = 0;
float pitch1 = 0, pitch2 = 0;
float roll1 = 0, roll2 = 0;
float mlev1 = 0, mlev2 = 0;
int had_connection = 0;

void loop() {
  if(!had_connection && millis() > 30000) lamp_mode = 1;
  if(!lamp_mode)
  {
    int dev_cnt = uMyo.getDeviceCount();
    if(dev_cnt > 0)
    {
      had_connection = 1;
      leds_intens = uMyo.getMuscleLevel(0);
      mlev1 = uMyo.getAverageMuscleLevel(0);
      pitch1 = uMyo.getPitch(0);
      float rr = roll1;
      roll1 = uMyo.getRoll(0);
      roll1_spd *= 0.95;
      roll1_spd += 0.05 * (roll1 - rr);
    }
    if(dev_cnt > 1)
    {
      leds_intens2 = uMyo.getMuscleLevel(1);
      mlev2 = uMyo.getAverageMuscleLevel(1);
      pitch2 = uMyo.getPitch(1);
      float rr = roll2;
      roll2 = uMyo.getRoll(1);
      roll2_spd *= 0.95;
      roll2_spd += 0.05 * (roll2 - rr);
    }
  }
  uint32_t ms = millis();
  int tm = ms%16000;
  float phase = tm - 8000;
  if(phase < 0) phase = -phase;
  phase /= 8000.0;
  int tm2 = ms%13000;
  float phase2 = tm2 - 6500;
  if(phase2 < 0) phase2 = -phase2;
  phase2 /= 6500.0;
  for(int x = 1; x < NUM_LEDS; x++)
  {
    leds[x] = CRGB(0, 0, 0);
  }

  float dt = (ms - prev_ms) * 0.001;
  prev_ms = ms;
  for(int p = 0; p < pulse1.pulse_count; p++)
  {
    pulse1.muscle_pulses[p] += pulse1.travel_speed * dt;
    if(pulse1.muscle_pulses[p] > 55) remove_pulse(p, &pulse1);
  }
  for(int p = 0; p < pulse2.pulse_count; p++)
  {
    pulse2.muscle_pulses[p] += pulse2.travel_speed * dt;
    if(pulse2.muscle_pulses[p] > 55) remove_pulse(p, &pulse2);
  }

  float rel_led_intens = leds_intens - 50;
  float rel_led_intens2 = leds_intens2 - 50;
  if(rel_led_intens < 0) rel_led_intens = 0;
  if(rel_led_intens2 < 0) rel_led_intens2 = 0;
  rel_led_intens /= 400.0;
  rel_led_intens2 /= 400.0;
  rel_led_intens *= 3.0;
  rel_led_intens2 *= 3.0;
  if(rel_led_intens > 1) rel_led_intens = 1;
  if(rel_led_intens2 > 1) rel_led_intens2 = 1;
  pulse1.travel_speed = 45 + 30*rel_led_intens;
  pulse2.travel_speed = 45 + 30*rel_led_intens2;
  float freq = 5.0*rel_led_intens;
  float freq2 = 5.0*rel_led_intens2;
  int rr = rand()%100000;
  int rr2 = rand()%100000;
  float prob = dt * freq;
  float prob2 = dt * freq2;
//  if(rr < 100000.0*prob) add_pulse(&pulse1);
//  if(rr2 < 100000.0*prob2) add_pulse(&pulse2);
  int interval = 10000;
  int interval2 = 10000;
  if(rel_led_intens > 0.1)
      interval = 800 - 700*rel_led_intens;
  if(rel_led_intens2 > 0.1)
      interval2 = 800 - 700*rel_led_intens2;
  if(ms - pulse1.last_pulse_time > interval) add_pulse(&pulse1);
  if(ms - pulse2.last_pulse_time > interval2) add_pulse(&pulse2);

  int pulse_r = 0;//-55 + 30*rel_led_intens;
  int pulse_g = 60 + 40*rel_led_intens;
  int pulse_b = 60 + 40*rel_led_intens;
  pulse_r = pulse_g;
  int led_r = 10;
  int led_g = 0;//5 + phase*5;
  int led_b = 0;//15 - phase*5;
  if(pulse_r < 0) pulse_r = 0;
  if(pulse_r > 10) pulse_b -= (pulse_r - 10);
  for(int l = 0; l < 47; l++)
  {
    float min_dx = 100;
    for(int p = 0; p < pulse1.pulse_count; p++)
    {
      float dx = pulse1.muscle_pulses[p] - l;
      if(dx < 0) dx = -dx;
      if(dx < min_dx) min_dx = dx;
    }
    int lr = led_r, lg = led_g, lb = led_b;
    if(min_dx < 1) lr = pulse_r, lg = pulse_g, lb = pulse_b;
    leds[1+33*2+47-2-l] = CRGB(lr, lg, lb); 
    min_dx = 100;
    for(int p = 0; p < pulse2.pulse_count; p++)
    {
      float dx = pulse2.muscle_pulses[p] - l;
      if(dx < 0) dx = -dx;
      if(dx < min_dx) min_dx = dx;
    }
    lr = led_r, lg = led_g, lb = led_b;
    if(min_dx < 1) lr = pulse_r, lg = pulse_g, lb = pulse_b;
    
    leds[1+33*2+47-1+l] = CRGB(lr, lg, lb); 
  }

  int mode1 = 0;
  int mode2 = 0;
//pitch: large = down, low = up
  if(pitch1 > 2) mode1 = 1;
  if(pitch2 > 2) mode2 = 1;

  if(1)
  {
    float r1, g1, b1;
    float r2, g2, b2;
    int hue1 = 120 + roll1*150;
    int hue2 = 120 + roll2*150;
    if(hue1 < 0) hue1 += 360;
    if(hue1 >= 360) hue1 -= 360;
    if(hue2 < 0) hue2 += 360;
    if(hue2 >= 360) hue2 -= 360;
    hsv2rgb(hue1, 100, 50, &r1, &g1, &b1);
    hsv2rgb(hue2, 100, 50, &r2, &g2, &b2);
    int level1 = 1.6*(mlev1 - 80);
    int level2 = 1.6*(mlev2 - 80);
//    int val1 = mlev1/10 - 3;
//    int val2 = mlev2/10 - 3;
    int val1 = sqrt(mlev1)*2.5 - 20;
    int val2 = sqrt(mlev2)*2.5 - 20;
    if(val1 > 40) val1 = 40;
    if(val1 < 0) val1 = 0;
    if(val2 > 40) val2 = 40;
    if(val2 < 0) val2 = 0;


    static float alpha1 = 0, alpha2 = 0;
    float w1 = 2000.0*roll1_spd;
    float w2 = 2000.0*roll2_spd;
    alpha1 += dt*w1;
    alpha2 += dt*w2;
    if(alpha1 > 3.14159*2) alpha1 -= 3.14159*2;
    if(alpha2 > 3.14159*2) alpha2 -= 3.14159*2;
    
    for(int l = 0; l < 47; l++)
    {
      float angle = 0;
      angle = 3.14159*0.25*0.13*l;
      float da1 = alpha1 - angle;
      float da2 = alpha2 - angle;
      int h1 = da1/3.14159*180;
      int h2 = da2/3.14159*180;
      while(h1 < 0) h1 += 360;
      while(h2 < 0) h2 += 360;
      while(h1 > 360) h1 -= 360;
      while(h2 > 360) h2 -= 360;
      float r, g, b;
      int rr, gg, bb;
      
      int idx1 = 1+33*2+47-2-l;
      int idx2 = 1+33*2+47-1+l;
      if(mode1 == 0)
      {
        int r = rand()%10000;
        if(level1 > r) leds[idx1] = CRGB(r1, g1, b1);
        else leds[idx1] = CRGB(0, 0, 0);
      }
      if(mode1 == 1)
      {
        hsv2rgb(h1, 100, val1, &r, &g, &b);
        rr = r; gg = g; bb = b;
        leds[idx1] = CRGB(rr, gg, bb);
      }
      if(mode2 == 0)
      {
        int r = rand()%10000;
        if(level2 > r) leds[idx2] = CRGB(r2, g2, b2);
        else leds[idx2] = CRGB(0, 0, 0);
      }
      if(mode2 == 1)
      {
        hsv2rgb(h2, 100, val2, &r, &g, &b);
        rr = r; gg = g; bb = b;
        leds[idx2] = CRGB(rr, gg, bb);
      }
    }
    for(int l = 0; l < 33; l++)
    {
      float angle = 0;
      if(l < 11) angle = 3.14159*0.667*0.091*l;
      else if(l < 22) angle = 3.14159*0.667 + 3.14159*0.667*0.091*(l-11);
      else angle = 3.14159*0.667*2 + 3.14159*0.667*0.091*(l-22);
      float da1 = alpha1 - angle;
      float da2 = alpha2 - angle;
      int h1 = da1/3.14159*180;
      int h2 = da2/3.14159*180;
      while(h1 < 0) h1 += 360;
      while(h2 < 0) h2 += 360;
      while(h1 > 360) h1 -= 360;
      while(h2 > 360) h2 -= 360;
      float r, g, b;
      int rr, gg, bb;
            
      if(mode1 == 0)
      {
        int r = rand()%10000;
        if(level1 > r) leds[1+l] = CRGB(r1, g1, b1);
        else leds[1+l] = CRGB(0, 0, 0);
      }
      if(mode1 == 1)
      {
        hsv2rgb(h1, 100, val1, &r, &g, &b);
        rr = r; gg = g; bb = b;
        leds[1+l] = CRGB(rr, gg, bb);
      }
      if(mode2 == 0)
      {
        int r = rand()%10000;
        if(level2 > r) leds[1+33+l] = CRGB(r2, g2, b2);
        else leds[1+33+l] = CRGB(0, 0, 0);
      }
      if(mode2 == 1)
      {
        hsv2rgb(h2, 100, val2, &r, &g, &b);
        rr = r; gg = g; bb = b;
        leds[1+33+l] = CRGB(rr, gg, bb);
      }
    }      
  }
  if(0)//(mode == 0) //HVS transition
  {
    static float alpha1 = 0, alpha2 = 0;
    float w1 = 5.0*pitch1;
    float w2 = 5.0*pitch2;
    alpha1 += dt*w1;
    alpha2 += dt*w2;
    if(alpha1 > 3.14159*2) alpha1 -= 3.14159*2;
    if(alpha2 > 3.14159*2) alpha2 -= 3.14159*2;
    for(int l = 0; l < 33; l++)
    {
      float angle = 0;
      if(l < 11) angle = 3.14159*0.667*0.091*l;
      else if(l < 22) angle = 3.14159*0.667 + 3.14159*0.667*0.091*(l-11);
      else angle = 3.14159*0.667*2 + 3.14159*0.667*0.091*(l-22);
      float da1 = alpha1 - angle;
      float da2 = alpha2 - angle;
      int h1 = da1/3.14159*180;
      int h2 = da2/3.14159*180;
      while(h1 < 0) h1 += 360;
      while(h2 < 0) h2 += 360;
      while(h1 > 360) h1 -= 360;
      while(h2 > 360) h2 -= 360;
      float r, g, b;
      int rr, gg, bb;
      hsv2rgb(h1, 100, 15, &r, &g, &b);
      rr = r; gg = g; bb = b;
      leds[1+l] = CRGB(rr, gg, bb);
      hsv2rgb(h2, 100, 15, &r, &g, &b);
      rr = r; gg = g; bb = b;
      leds[1+33+l] = CRGB(rr, gg, bb);
      
    }
  }

  if(lamp_mode)
  { 
  int active_idx = phase2 * NUM_LEDS;
  for(int x = 0; x < NUM_LEDS; x++)
  {
    int h_idx = x * 360 / NUM_LEDS + phase * 360;
    h_idx = h_idx%360;
    float r, g, b;
    hsv2rgb(h_idx, 100, 20, &r, &g, &b);
    r *= 0.5;
    leds[x] = CRGB(r, g, b);
    int dx = x - active_idx;
    if(dx < 0) dx = -dx;
    if(dx == 0) leds[x] = CRGB(0, 15, 20);
    if(dx == 1) leds[x] = CRGB(0, 15, 15);
    if(dx == 2) leds[x] = CRGB(0, 13, 5);
  }
  }
  FastLED.show();
//  return;
  Serial.print(uMyo.getAverageMuscleLevel(0));
  Serial.print(" ");
  Serial.println(uMyo.getAverageMuscleLevel(1));
  return;
//  Serial.print(uMyo.getDeviceCount());
  Serial.print(" ");
  Serial.print(pitch1);
  Serial.print(" ");
  Serial.print(roll1);
  Serial.print(" ");
  Serial.print(pitch2);
  Serial.print(" ");
  Serial.print(roll2);
  Serial.println(" ");
}

Credits

Frogolina

Frogolina

2 projects • 0 followers
I do a bunch of stuff in Ultimate Robotics

Comments