Hackster is hosting Hackster Holidays, Ep. 6: Livestream & Giveaway Drawing. Watch previous episodes or stream live on Monday!Stream Hackster Holidays, Ep. 6 on Monday!
hirotakaster
Published © MIT

LED Guitar

NeoPixel LED controlled by Particle Argon and 6-axis sensor.

BeginnerFull instructions provided1,252
LED Guitar

Things used in this project

Hardware components

Guitar
×1
ws2812b(neopixel)
×10
Argon
Particle Argon
×1
Inertial Measurement Unit (IMU) (6 deg of freedom)
Inertial Measurement Unit (IMU) (6 deg of freedom)
×1
3.7V 1200mAh LiPo
×1

Software apps and online services

Particle Build Web IDE
Particle Build Web IDE

Hand tools and fabrication machines

Titebond
Drill
sand paper(120, 240)
Acrylic rod(5mm)
epoxy resin

Story

Read more

Code

neopixel and MPU6050

Arduino
#include <MPU6050.h>
#include "Particle.h"
#include "neopixel.h"

SYSTEM_MODE(AUTOMATIC);
// SYSTEM_MODE(SEMI_AUTOMATIC);

#define PIXEL_PIN D2
#define PIXEL_COUNT 10
#define PIXEL_TYPE WS2812B

Adafruit_NeoPixel strip(PIXEL_COUNT, PIXEL_PIN, PIXEL_TYPE);
MPU6050 accelgyro;
int16_t ax, ay, az;
int16_t gx, gy, gz;
int rval = 0;
int gval = 0;
int bval = 0;

// Prototypes for local build, ok to leave in for Build IDE
void rainbow(uint8_t wait);
uint32_t Wheel(byte WheelPos);
int counter = 0;
bool remoteColor;

bool success = Particle.function("color", color);
int color(String extra) {
    if (!remoteColor) {
        remoteColor = true;
        if (extra.equals("RED"))
            colorWipe(strip.Color(255, 0, 0), 50);
        else if (extra.equals("GREEN"))
            colorWipe(strip.Color(0, 255, 0), 50);
        else if (extra.equals("BLUE"))
            colorWipe(strip.Color(0, 0, 255), 50);
        else if (extra.equals("RAINBOW"))
            rainbow(20);
        else if (extra.equals("RAINBOWCYLE"))
            rainbowCycle(20);
        else if (extra.equals("THEATERCHASE"))
              theaterChaseRainbow(50);
        remoteColor = false;
    }
    return 0;
}

void setup() {
    strip.begin();
    strip.show();
    Wire.begin();
    Serial.begin(9600);
    accelgyro.initialize();
    remoteColor = false;
}

void loop() {
    if (!remoteColor) {
        int16_t tmp_ax, tmp_ay, tmp_az;
        int16_t tmp_gx, tmp_gy, tmp_gz;
    
        int16_t diff_ax, diff_ay, diff_az;
        int16_t diff_gx, diff_gy, diff_gz;
    
        accelgyro.getMotion6(&tmp_ax, &tmp_ay, &tmp_az, &tmp_gx, &tmp_gy, &tmp_gz);
    
        diff_ax = tmp_ax - ax; diff_ay = tmp_ay - ay; diff_az  = tmp_az - az;
        diff_gx = tmp_gx - gx; diff_gy = tmp_gy - gy; diff_gz  = tmp_gz - gz;
        ax = tmp_ax; ay = tmp_ay; az = tmp_az;
        gx = tmp_gx; gy = tmp_gy; gz = tmp_gz;
        
        int tmp_rval = map(abs(diff_ax), 0, 0xFFFF/8, 0, 255);
        int tmp_gval = map(abs(diff_ay), 0, 0xFFFF/8, 0, 255);
        int tmp_bval = map(abs(diff_az), 0, 0xFFFF/8, 0, 255);
        
        if (tmp_rval > 255) tmp_rval = 255;
        if (tmp_gval > 255) tmp_gval = 255;
        if (tmp_bval > 255) tmp_bval = 255;
        rval = (tmp_rval + rval) / 2;
        gval = (tmp_gval + gval) / 2;
        bval = (tmp_bval + bval) / 2;
        
        Serial.print(rval);  Serial.print("\t");
        Serial.print(gval);  Serial.print("\t");
        Serial.print(bval);  Serial.print("\t");
        Serial.println("");
        
        for(int i = 0; i < strip.numPixels(); i++) {
            strip.setPixelColor(i, strip.Color(rval, gval, bval));
        }
        strip.show();
        delay(5);
    }
}


// Fill the dots one after the other with a color
void colorWipe(uint32_t c, uint8_t wait) {
  for(uint16_t i=0; i<strip.numPixels(); i++) {
    strip.setPixelColor(i, c);
    strip.show();
    delay(wait);
  }
}

void rainbow(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256; j++) {
    for(i=0; i<strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel((i+j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

// Slightly different, this makes the rainbow equally distributed throughout
void rainbowCycle(uint8_t wait) {
  uint16_t i, j;

  for(j=0; j<256*5; j++) { // 5 cycles of all colors on wheel
    for(i=0; i< strip.numPixels(); i++) {
      strip.setPixelColor(i, Wheel(((i * 256 / strip.numPixels()) + j) & 255));
    }
    strip.show();
    delay(wait);
  }
}

//Theatre-style crawling lights.
void theaterChase(uint32_t c, uint8_t wait) {
  for (int j=0; j<10; j++) {  //do 10 cycles of chasing
    for (int q=0; q < 3; q++) {
      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, c);    //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

//Theatre-style crawling lights with rainbow effect
void theaterChaseRainbow(uint8_t wait) {
  for (int j=0; j < 256; j++) {     // cycle all 256 colors in the wheel
    for (int q=0; q < 3; q++) {
      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, Wheel( (i+j) % 255));    //turn every third pixel on
      }
      strip.show();

      delay(wait);

      for (uint16_t i=0; i < strip.numPixels(); i=i+3) {
        strip.setPixelColor(i+q, 0);        //turn every third pixel off
      }
    }
  }
}

// Input a value 0 to 255 to get a color value.
// The colours are a transition r - g - b - back to r.
uint32_t Wheel(byte WheelPos) {
  WheelPos = 255 - WheelPos;
  if(WheelPos < 85) {
    return strip.Color(255 - WheelPos * 3, 0, WheelPos * 3);
  }
  if(WheelPos < 170) {
    WheelPos -= 85;
    return strip.Color(0, WheelPos * 3, 255 - WheelPos * 3);
  }
  WheelPos -= 170;
  return strip.Color(WheelPos * 3, 255 - WheelPos * 3, 0);
}

Credits

hirotakaster

hirotakaster

2 projects • 3 followers
programmer

Comments