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.

Light Controller

Summary

This assignment was very challenging for me. I started off working alone, being able to control 3 potentiometers with 3 RGB LEDs, which each showed either Red, Green, or Blue. Although, the pots were controlling the LEDs, I wanted there to just be 1 pot and 1 LED. And then I moved on to work with Jesal, who was having a different issue– he was using 1 LED and 1 Pot, but wasn’t able to control the LED in the way he wanted. We began working together and eventually were able to move to 1 LED being controlled by 3 potentiometers. We had issues with mapping along the way, for example, when we were at 672, which was our max for the pots, the LEDs were showing zero values. Regardless, of the mapping working in the opposite way, we were happy it was working. Then we moved to adding a switch to turn everything off and on. For whatever reason when I ran into this step during the past week, it’s where I had the most trouble. We eventually decided to work on the enclosure and worry about the switch after. Jesal then laser cut a shoe box we had, and I soldered the pots, LEDs, and button. However, when we came back just to assemble everything, nothing worked! We were reading completely different values for the pots. And without understanding, the LED now just blinks between all of the colors. Ultimately, we decided to cut our losses and house everything and hope a miracle would ensue in the day to come.

Circuit Diagram

Code       

const int analogInPin1 = A0; //red
const int analogInPin2 = A1; //green
const int analogInPin3 = A2; //blue
const int analogOutPin1 = 9; // Analog output pin that the LED is attached to
const int analogOutPin2 = 10;
const int analogOutPin3 = 11;

int turnon = 6;
int previousButtonState = LOW;

int sensorValue1 = 0;
int outputValue1 = 0;
int sensorValue2 = 0;
int outputValue2 = 0;
int sensorValue3 = 0;
int outputValue3 = 0;

//#define COMMON_ANODE
void setup() {
// initialize serial communications at 9600 bps:
Serial.begin(9600);
pinMode(turnon, INPUT);

////pinMode(LEDpin, OUTPUT);
// pinMode(turnon, INPUT);
// digitalWrite(turnon, HIGH); // turn on pullup resistor

}

void loop() {
// if(digitalRead(turnon) == HIGH) {
Serial.println(“working”);

// read the analog in value:
sensorValue1 = analogRead(analogInPin1);
// map it to the range of the analog out:
outputValue1 = map(sensorValue1, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin1, outputValue1);

sensorValue2 = analogRead(analogInPin2);
// map it to the range of the analog out:
outputValue2 = map(sensorValue2, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin2, outputValue2);

sensorValue3 = analogRead(analogInPin3);
// map it to the range of the analog out:
outputValue3 = map(sensorValue3, 0, 1023, 0, 255);
// change the analog out value:
analogWrite(analogOutPin3, outputValue3);

// print the results to the serial monitor:
Serial.print(“sensor1 = “);
Serial.print(sensorValue1);
Serial.print(“\t output1 = “);
Serial.println(outputValue1);

Serial.print(“sensor2 = “);
Serial.print(sensorValue2);
Serial.print(“\t output2= “);
Serial.println(outputValue2);

Serial.print(“sensor3 = “);
Serial.print(sensorValue3);
Serial.print(“\t output3 = “);
Serial.println(outputValue3);

// wait 2 milliseconds before the next loop
// for the analog-to-digital converter to settle
// after the last reading:
delay(400);
// }
//else {
// if (digitalRead(turnon) == LOW) {
// Serial.println(“fuck your mom”);
//// digitalWrite(analogInPin1) = LOW;
//// digitalWrite(analogInPin2) = LOW;
//// digitalWrite(analogInPin3) = LOW;
// digitalRead(turnon) == LOW;
// }

}

 

 

Getting 3 Pots to control 3 RGB LEDs

1 Pot controlling 1 RGB LED

Board before soldering

Front of controller

Back of controller

Sources

https://www.arduino.cc/en/Reference/BooleanVariables

https://www.arduino.cc/en/Tutorial/AnalogInOutSerial

Turn ON an LED with a Button and Arduino – Tutorial #4

https://gist.github.com/stelles/8189613