Music Player

This assignment I had more of a difficult time setting up the circuit than focusing on the design. I eventually got the buttons to work with an output of a vibration, but still ran into a few hiccups. Ultimately, this project was more of the issues I ran into, then making something work. I am planning on re-doing this project for the final by using a vibration motor without the haptic controller. I think the library gave me a lot of issues.

When I eventually got the circuit working, I thought of trying out some housing ideas, just to get the feel for how someone would interact with the controller. I found a small cardboard box and cut out a spot for the buttons.

Since it wasn’t laser cut or anything, I just put some electric tape over it to clean up the look. Clearly, from below, the button sizes didn’t work for this.

Code

#include <Adafruit_DRV2605.h>
#include <Wire.h>

int lastOnOff = LOW; //start/stop button

Adafruit_DRV2605 drv;

//keyboard variables

//int buttonA = 3;
//int buttonD = 4;
int first = 5;
int second = 6;
int third = 7;
int fourth = 8;
int fifth = 9;

int previousButtonStateFirst = LOW;
int previousButtonStateSecond = LOW;
int previousButtonStateThird = LOW;
int previousButtonStateFourth = LOW;
int previousButtonStateFifth = LOW;
void setup() {
Serial.begin(9600);
// put your setup code here, to run once:

pinMode(first, INPUT);
pinMode(second, INPUT);
pinMode(third, INPUT);
pinMode(fourth, INPUT);
pinMode(fifth, INPUT);

drv.begin();
drv.selectLibrary(1);
//I2C trigger sends “go”
//default internal trigger when sending GO
drv.setMode(DRV2605_MODE_INTTRIG);

}

void loop() {
// put your main code here, to run repeatedly:
int buttonStateFirst = digitalRead(first);

if ((buttonStateFirst != previousButtonStateFirst) && (buttonStateFirst == HIGH)) {

Serial.println(“1st working”);
drv.setWaveform(0, 84); //effect
drv.setWaveform(1, 0); // end wave form

//play the effect
drv.go();
//wait a bit
Serial.write(49);
delay(500);
} else {
drv.setWaveform(0, 0); //effect
drv.setWaveform(1, 0); // end wave form

//play the effect
drv.go();
//wait a bit
Serial.write(49);
delay(500);
}
previousButtonStateFirst = first;

int buttonStateSecond = digitalRead(second);
if ((buttonStateSecond != previousButtonStateSecond) && (buttonStateSecond == HIGH)) {
Serial.println(“2nd working”);
drv.setWaveform(0, 84); //effect
drv.setWaveform(1, 0); // end wave form

//play the effect
drv.go();
//wait a bit
Serial.write(49);
} else {
drv.setWaveform(0, 0); //effect
drv.setWaveform(1, 0); // end wave form

//play the effect
drv.go();
//wait a bit
Serial.write(49);
}
previousButtonStateSecond = buttonStateSecond;

int buttonStateThird = digitalRead(third);
if ((buttonStateThird != previousButtonStateThird) && (buttonStateThird == HIGH)) {
Serial.println(“3rd working”);
drv.setWaveform(0, 84); //effect
drv.setWaveform(1, 0); // end wave form

//play the effect
drv.go();
//wait a bit
Serial.write(49);
} else {
drv.setWaveform(0, 0); //effect
drv.setWaveform(1, 0); // end wave form

//play the effect
drv.go();
//wait a bit
Serial.write(49);
}
previousButtonStateThird = buttonStateThird;

int buttonStateFourth = digitalRead(fourth);
if ((buttonStateFourth != previousButtonStateFourth) && (buttonStateFourth == HIGH)) {
Serial.println(“4th working”);
drv.setWaveform(0, 84); //effect
drv.setWaveform(1, 0); // end wave form

//play the effect
drv.go();
//wait a bit
Serial.write(49);
} else {
drv.setWaveform(0, 0); //effect
drv.setWaveform(1, 0); // end wave form

//play the effect
drv.go();
//wait a bit
Serial.write(49);
}
previousButtonStateFourth = buttonStateFourth;

int buttonStateFifth = digitalRead(fifth);
if ((buttonStateFifth != previousButtonStateFifth) && (buttonStateFifth == HIGH)) {
Serial.println(“5th working”);
drv.setWaveform(0, 84); //effect
drv.setWaveform(1, 0); // end wave form

//play the effect
drv.go();
//wait a bit
Serial.write(49);
} else {
drv.setWaveform(0, 0); //effect
drv.setWaveform(1, 0); // end wave form

//play the effect
drv.go();
//wait a bit
Serial.write(49);
}
previousButtonStateFifth = buttonStateFifth;
}

Weird things

Below I have a screenshot of what happens in the serial monitor. Basically, when I open the serial monitor it just starts printings 1s. I have combed through my code many times and have no idea where the 1 is coming from. However, the sketch works–when I press the buttons I get a vibration and it prints in the serial monitor that is has been pressed. This doesn’t work continuously though. It seems to only work with a few buttons at a time. Or just works for a certain amount of time and then stops working.

If I take out the “else” statement, it only prints out that the button has been pressed, but there is a “1” printing before each line. Why?

If I put it back in, but comment out “drv.go” for the vibration effect, this happens. But no vibration.

If I uncomment that line, but comment out “Serial.write(49)”, then it prints and the vibration works. But why the “1”?

By adding another button to the equation, the serial monitor still print quite normally, with the exception of the “1” before the line. But it does not vibrate.