LED Blinky Guitar

LED Blinky Guitar

October 1, 2019 DIY / Maker 0

LEDs in a ‘Squire II’ #electricguitar triggered by a magnetometer that detects movement like a compass. #🎸 Originally used a circuit my dad made me to play with in 89 at 6yo. By high school in the late 90s i bought the first white and blue LEDs to appear at RadioShack and drilled some holes. The wire is from an old Univac computer. there are 12 LEDs, two of which are bi-color red/green. I didn’t have an accelerometer lying around, maybe next time, but this works to make the sparkle match my moves for the most part. used every pin on the #arduino#promicro#🎛 the old circuit died, but not before i played with it in Rooftop Ridicule and Wax Pig Melting. nicks from hitting cymbals with the headstock.

note the lil red killswitch, it doesn’t short the signal to ground the normie way, it shorts the lugs on the tone pot, so it’s less poppy but still pulses nicely. almost wah ish.

there’s some rudimentary midi response too, but it’s kinda lame.

View this post on Instagram

#LEDs in a ‘Squire II’ #electricguitar triggered by a magnetometer that detects movement like a compass. #🎸 Originally used a circuit my dad made me to play with in 89 at 6yo. By high school in the late 90s i bought the first white and blue LEDs to appear at RadioShack and drilled some holes. The wire is from an old Univac computer. there are 12 LEDs, two of which are bi-color red/green. I didn’t have an accelerometer lying around, maybe next time, but this works to make the sparkle match my moves for the most part. used every pin on the #arduino #promicro #🎛 the old circuit died, but not before i played with it in Rooftop Ridicule and Wax Pig Melting. nicks from hitting cymbals with the headstock. note the lil red killswitch, it doesn’t short the signal to ground the normie way, it shorts the lugs on the tone pot, so it’s less poppy but still pulses nicely. almost wah ish. #diyguitar #guitarhack #indieguitar #musicelectronics #diymusic #musichack #makersgonnamake #makermusic

A post shared by Joseph Wozniak📟 (@wozsupposedly) on

code for arduino pro micro / leonardo
*NOTEs
1. some of the LEDs were wired with positive as the common, but I also had some bi-color LEDs in there with common-negative, so the high/low on/off situation is reversed for 4 of the lights.
2. the pro micro only has 100ma to give, 20ma per pin, so we only light up one LED at a time.

#include <SPI.h>
#include <Arduino.h>
#include <Wire.h>
#include <DFRobot_QMC5883.h>
#include <MIDIUSB.h>

DFRobot_QMC5883 compass;

#define channel 13
#define space 60

float oldhead;
float headingDegrees;
int change;
int oldchange;
int light;
bool midinoteon;

#define df 2

void setup() {
  // Serial.begin(9600);     // opens serial port, sets data rate to 9600 bps
  Serial.begin(115200);
  while (!compass.begin())
  {
    Serial.println("no QMC5883");
    delay(1000);
  }

  pinMode(A0, INPUT); //knob
  pinMode(19, INPUT_PULLUP); //button
  
  pinMode(0, OUTPUT); // bicolor leds
  pinMode(1, OUTPUT);
  pinMode(20, OUTPUT);
  pinMode(21, OUTPUT);

  pinMode(4, OUTPUT); // whatever leds
  pinMode(5, OUTPUT);
  pinMode(6, OUTPUT);
  pinMode(7, OUTPUT);
  pinMode(8, OUTPUT);
  pinMode(9, OUTPUT);
  pinMode(10, OUTPUT);
  pinMode(14, OUTPUT);
  pinMode(15, OUTPUT);
  pinMode(16, OUTPUT);

  randomSeed(analogRead(A9));

  if (compass.isHMC()) {
    //   Serial.println("Initialize HMC5883");
    compass.setRange(HMC5883L_RANGE_1_3GA);
    compass.setMeasurementMode(HMC5883L_CONTINOUS);
    compass.setDataRate(HMC5883L_DATARATE_15HZ);
    compass.setSamples(HMC5883L_SAMPLES_8);
  }
  else if (compass.isQMC()) {
    //    Serial.println("Initialize QMC5883");
    compass.setRange(QMC5883_RANGE_2GA);
    compass.setMeasurementMode(QMC5883_CONTINOUS);
    compass.setDataRate(QMC5883_DATARATE_50HZ);
    compass.setSamples(QMC5883_SAMPLES_8);
  }
}

void loop() {
 
  if (digitalRead(19)){
mag();
  }else{
  cycle();
  }
  }

void mag() {
  Vector norm1 = compass.readNormalize();
  Vector norm2 = compass.readNormalize();
  Vector norm3 = compass.readNormalize();
  
  // Calculate heading
  float heading = 
    ((atan2(norm1.YAxis, norm1.XAxis)) +
     (atan2(norm2.YAxis, norm2.XAxis)) +
     (atan2(norm3.YAxis, norm3.XAxis))) / 3;

  float declinationAngle = (4.0 + (26.0 / 60.0)) / (180 / PI);
  heading += declinationAngle;

  if (heading < 0) {
    heading += 2 * PI;
  }

  if (heading > 2 * PI) {
    heading -= 2 * PI;
  }

  headingDegrees = heading * 180 / PI;

  if ((oldhead - headingDegrees) < 0) {
    change = round(headingDegrees - oldhead);
  } else {
    change = round(oldhead - headingDegrees);
  }

  oldhead = headingDegrees;

    if (change < 5) {
      change = 0;
    }
  if (change != oldchange) {
    if (change!=0){

  light = round(random(14));
  dolight();

    }  
    oldchange = change;
  }

if (midinoteon){
cycle();
}

}

void cycle(){
      if(random(2)){
        light++;
        }else{
          light--;
          }
          if(light<0) light=13;
          if(light>13) light=0;

if (midinoteon&&!digitalRead(19)){
    light = round(random(14));
}

dolight();

dodelay();

  }

void dodelay(){
for(int i=0;i<(256-analogRead(A0)/4);i++){
delay(1);
midicheck();
  }
}  

void midicheck(){
      midiEventPacket_t rx = MidiUSB.read();
  switch (rx.header) {
    case 0:
      break; //No pending events
    case 0x9:
    midinoteon = true;
      break;
    case 0x8:
    midinoteon = false;
      break;
  }
  }  

  void dolight(){
if (light==0){ digitalWrite(9,LOW);} else{ digitalWrite(9,HIGH);}
if (light==1){ digitalWrite(5,LOW);} else{ digitalWrite(5,HIGH);}
if (light==2){ digitalWrite(8,LOW);} else{ digitalWrite(8,HIGH);}
if (light==3){ digitalWrite(4,LOW);} else{ digitalWrite(4,HIGH);}
if (light==4){ digitalWrite(6,LOW);} else{ digitalWrite(6,HIGH);}
if (light==5){ digitalWrite(7,LOW);} else{ digitalWrite(7,HIGH);}
if (light==6){ digitalWrite(1,HIGH);} else{ digitalWrite(1,LOW);}
if (light==7){ digitalWrite(21,HIGH);} else{ digitalWrite(21,LOW);}
if (light==8){ digitalWrite(10,LOW);} else{ digitalWrite(10,HIGH);}
if (light==9){ digitalWrite(14,LOW);} else{ digitalWrite(14,HIGH);}
if (light==10){ digitalWrite(15,LOW);} else{ digitalWrite(15,HIGH);}
if (light==11){ digitalWrite(16,LOW);} else{ digitalWrite(16,HIGH);}
if (light==12){ digitalWrite(0,HIGH);} else{ digitalWrite(0,LOW);}
if (light==13){ digitalWrite(20,HIGH);} else{ digitalWrite(20,LOW);}      
    }