pComp Final Update

Started soldering and testing my connections. My 10k sliding potentiometer is working when tested with this code:

void setup() {
Serial.begin(9600);
}
void loop() {
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
}

Sliding Potentiometer from Marco Wylie on Vimeo.

And the other potentiometer for the volume is working as well.

Potentiometer from Marco Wylie on Vimeo.

Once I got home with all my soldered pieces I assembled the code for the two potentiometers and three buttons to print the sensor values.

const int pinButton2 = 2;
const int pinButton3 = 3;
const int pinButton4 = 4;
void setup() {
pinMode(pinButton2, INPUT);
pinMode(pinButton3, INPUT);
pinMode(pinButton4, INPUT);
Serial.begin(9600);
}
void loop() {
int stateButton2 = digitalRead(pinButton2);
int stateButton3 = digitalRead(pinButton3);
int stateButton4 = digitalRead(pinButton4);
Serial.println(stateButton2);
Serial.println(stateButton3);
Serial.println(stateButton4);
delay(20);
int sensorValue = analogRead(A0);
Serial.println(sensorValue);
int sensorValue1 = analogRead(A1);
Serial.println(sensorValue1);
}

Final progress from Marco Wylie on Vimeo.

I’m having a lot of trouble making a serial connection between my Arduino, the three buttons, and my p5.js sketch. Here is my current Arduino sketch:

const int pinButton2 = 2;
const int pinButton3 = 3;
const int pinButton4 = 4;
int lastButtonState = LOW;
int buttonPressCount = 0;
void setup() {
pinMode(pinButton2, INPUT);
pinMode(pinButton3, INPUT);
pinMode(pinButton4, INPUT);
Serial.begin(9600);
}
void loop() {
char incoming = Serial.read(); // read incoming bytes
if (incoming == 'P') { // if you get P
digitalWrite(2, HIGH); // Play is Pressed
}
int currentButtonState = digitalRead(2); //read the play button
if (currentButtonState != lastButtonState) { // if the button changed
buttonPressCount++; // increment buttonPressCount
Serial.print('P'); // send a P
Serial.println(buttonPressCount);
}
// int stateButton2 = digitalRead(pinButton2);
// int stateButton3 = digitalRead(pinButton3);
// int stateButton4 = digitalRead(pinButton4);
// Serial.println(stateButton2);
// Serial.println(stateButton3);
// Serial.println(stateButton4);
// delay(20);
lastButtonState = currentButtonState; // save the current state for next time
// int sensorValue = analogRead(A0);
// Serial.println(sensorValue);
// int sensorValue1 = analogRead(A1);
// Serial.println(sensorValue1);
}

Every time I press the button on my breadboard I get a serial monitor reading of “P” but then I get another “P” when I release the button as well. This is making the song clips play twice and distorting the sound heavily in my p5.js sketch.

Button Press from Marco Wylie on Vimeo.