Good Morning!
I'm working on simple stuff... But I'd need some help! I'm trying to code something easy: when a button is pushed, a number is printed in the serial monitor. However, there is a problem.
I need the Arduino to send a continuous number to the serial monitor. This only happens when the third button is pressed. When the first or the second buttons are pressed, the number appears with a "0" in front. And this is not good for me! Because the movies that I would like to play are not played if a zero is sent.
I think that is a debouncing problem... but I don't know how to fix it ![]()
I attach the code and a few screenshots of what I would need for the project, and what I am having now.
Thank you in advance for everything!!
/*
WAITING ROOM
INSTALLATION CODED BY Jordi Farreras).
The code sets up a few buttons. When they are pushed,
a number is sent to processing. Then, depending on
the button, a video is played.
*/
//1. DECLARE PINS
int switchPin1 = 4; // Switch connected to pin 4
int switchPin2 = 5; // Switch connected to pin 5
int switchPin3 = 6; // Switch connected to pin 6
//2. SET EVERYTHING UP
void setup() {
//Serial Port begin
Serial.begin (19200);
//Define inputs and outputs
pinMode(switchPin1, INPUT_PULLUP);
pinMode(switchPin2, INPUT_PULLUP);
pinMode(switchPin3, INPUT_PULLUP);
}
//3. THE MAGIC HAPPENS
void loop()
{
// CODE BUTTONS
if (digitalRead(switchPin1) == LOW) {
Serial.println(1);
delay(1000);
}
if (digitalRead(switchPin2) == LOW) {
Serial.println(2);
delay(1000);
}
if (digitalRead(switchPin3) == LOW) {
Serial.println(3);
delay(1000);
}
else {
delay(1000);
Serial.println(0);
delay(50);
}
}

