Arduino Code - TheResistanceBand/theResistanceBand GitHub Wiki

Instruments Arduino

/*
 * The Resistance Band
 * Interactive Devices Final Project
 * By: Marco White, Brett Leibowitz, and Arpit Sheth
 * Last Modified: 5/8/18
 */

// Libraries
#include "Adafruit_VL53L0X.h"

// Define potentiometer pin
#define drum1Pin A0
#define drum2Pin A1
#define drum3Pin A2
#define flexPin A3

// Program variables
int drum1Val = 0;
int drum2Val = 0;
int drum3Val = 0;
int thereminVal = 0;
int flexVal = 0;
bool isDrum1Playing = false;
bool isDrum2Playing = false;
bool isDrum3Playing = false;
bool isThereminPlaying = false;
bool isFlexPlaying = false;

// Theremin
Adafruit_VL53L0X lox = Adafruit_VL53L0X();

void setup() {
  // Set up the LCD's number of columns and rows
  // lcd.begin(16, 2);
  // Setup serial monitor
   Serial.begin(9600);
   lox.begin();
}

void loop() {
  // Read the fsrValue
  drum1Val = analogRead(drum1Pin);
  drum2Val = analogRead(drum2Pin);
  drum3Val = analogRead(drum3Pin);
  flexVal = analogRead(flexPin);
  
  if (drum1Val > 100 && !isDrum1Playing) {
    isDrum1Playing = true;
    Serial.println("drum1");
  } else if (drum1Val < 10 && isDrum1Playing) {
    isDrum1Playing = false;
  }

  if (drum2Val > 100 && !isDrum2Playing) {
    Serial.println("drum2");
    isDrum2Playing = true;
  } else if (drum2Val < 10 && isDrum2Playing) {
    isDrum2Playing = false;
  }

  if (drum3Val > 100 && !isDrum3Playing) {
    Serial.println("drum3");
    isDrum3Playing = true;
  } else if (drum3Val < 10 && isDrum3Playing) {
    isDrum3Playing = false;
  }

//  if (thereminVal > 100 && !isPlaying) {
//    Serial.println("theremin");
//    isPlaying = true;
//  } else if (thereminVal < 20 && isPlaying) {
//    isPlaying = false;
//  }

//  Serial.println(flexVal);
  if (flexVal < 300 && !isFlexPlaying) {
    Serial.println("flex");
    isFlexPlaying = true;
  } else if (flexVal > 450 && isFlexPlaying) {
    isFlexPlaying = false;
  }

  // Sensor measure object
  VL53L0X_RangingMeasurementData_t measure;

  // Get the measurement
  lox.rangingTest(&measure, false); // pass in 'true' to get debug data printout!

  // Check for a valid measurement
  if (measure.RangeStatus != 4) {  // phase failures have incorrect data
    thereminVal = measure.RangeMilliMeter;
  }
  if (thereminVal >= 60 && thereminVal <= 150) {
    if (!isThereminPlaying) {
      Serial.println("theremin1");
    }
    isThereminPlaying = true;
  } else if (thereminVal >= 151 && thereminVal <= 250) {
    if (!isThereminPlaying) {
      Serial.println("theremin2");
    }
    isThereminPlaying = true;
  } else if (thereminVal >= 251) {
    if (!isThereminPlaying) {
      Serial.println("theremin3");
    }
    isThereminPlaying = true;
  } else {
    isThereminPlaying = false;
  }
  
}

Music Visualizer Arduino

/*
 * The Resistance Band
 * Interactive Devices Final Project
 * By: Marco White, Brett Leibowitz, and Arpit Sheth
 * Last Modified: 5/8/18
 */

// Include libraries
#include <Adafruit_DotStar.h>

// Pin Definitions
#define EQUALIZER A5 //MSGEQ7 OUT
#define STROBEPIN 12 //MSGEQ7 STROBE
#define RESETPIN 13  //MSGEQ7 RESET
#define LEDDATA 4
#define LEDCLK 5

// Program constants
#define NUMPIXELS 107
#define THRESH 80

// Program variables
int spectrum[6];

// Setup the LED strip
Adafruit_DotStar strip = Adafruit_DotStar(NUMPIXELS, LEDDATA, LEDCLK, DOTSTAR_BGR);

void setup() {
  // Setup serial monitor
  Serial.begin(9600);
  // Initialize pins
  pinMode(STROBEPIN, OUTPUT);
  pinMode(RESETPIN, OUTPUT);
  digitalWrite(RESETPIN, LOW);
  digitalWrite(STROBEPIN, HIGH);
  // Initialize LED strip
  strip.begin();
  strip.show();
}

void loop() {
  // Get frequency spectrum information
  // Reset the equalizer chip
  digitalWrite(RESETPIN, HIGH);
  digitalWrite(RESETPIN, LOW);
  for (int i=0; i<=6; i++) {
    // Write the strobe pin to low in order to get the value for the next frequency band
    digitalWrite(STROBEPIN, LOW);
    delay(5);
    // Skip the 16kHz band
    if (i != 0) {
      // Get the value for the current frequency band
      spectrum[i-1] = analogRead(EQUALIZER);
      // Update the LED strip
      switch(i-1) {
        case 0:
          for (int j=34; j<=71; j++) {
            strip.setPixelColor(j, constrain(map(spectrum[i-1], THRESH, 1023, 0, 255), 0, 255), 0, 0);  
          }
          break;
        case 1:
          for (int j=24; j<=33; j++) {
            strip.setPixelColor(j, constrain(map(spectrum[i-1], THRESH, 1023, 0, 250), 0, 250), constrain(map(spectrum[0], THRESH, 1023, 0, 150), 0, 150), 0);  
          }
          for (int j=72; j<=81; j++) {
            strip.setPixelColor(j, constrain(map(spectrum[i-1], THRESH, 1023, 0, 250), 0, 250), constrain(map(spectrum[0], THRESH, 1023, 0, 150), 0, 150), 0);  
          }
          break;
        case 2:
          for (int j=14; j<=23; j++) {
            strip.setPixelColor(j, constrain(map(spectrum[i-1], THRESH, 1023, 0, 200), 0, 200), constrain(map(spectrum[0], THRESH, 1023, 0, 200), 0, 200), 0);
          }
          for (int j=82; j<=91; j++) {
            strip.setPixelColor(j, constrain(map(spectrum[i-1], THRESH, 1023, 0, 200), 0, 200), constrain(map(spectrum[0], THRESH, 1023, 0, 200), 0, 200), 0);
          }
          break;
        case 3:
          for (int j=10; j<=14; j++) {
            strip.setPixelColor(j, 0, constrain(map(spectrum[i-1], THRESH, 1023, 0, 255), 0, 255), 0);
          }
          for (int j=92; j<=96; j++) {
            strip.setPixelColor(j, 0, constrain(map(spectrum[i-1], THRESH, 1023, 0, 255), 0, 255), 0);
          }
          break;
        case 4:
          for (int j=5; j<=9; j++) {
            strip.setPixelColor(j, 0, 0, constrain(map(spectrum[i-1], THRESH, 1023, 0, 255), 0, 255));
          }
          for (int j=97; j<=101; j++) {
            strip.setPixelColor(j, 0, 0, constrain(map(spectrum[i-1], THRESH, 1023, 0, 255), 0, 255));
          }
          break;
        case 5:
          for (int j=0; j<=4; j++) {
            strip.setPixelColor(j, constrain(map(spectrum[i-1], THRESH, 1023, 0, 200), 0, 200), 0, constrain(map(spectrum[0], THRESH, 1023, 0, 200), 0, 200));
          }
          for (int j=102; j<=106; j++) {
            strip.setPixelColor(j, constrain(map(spectrum[i-1], THRESH, 1023, 0, 200), 0, 200), 0, constrain(map(spectrum[0], THRESH, 1023, 0, 200), 0, 200));
          }
          break;
      }
      strip.show();
    }
    // Once you've got the frequency band info write the strobe pin to high
    digitalWrite(STROBEPIN, HIGH);
  }
}