Hi im new to arduino and i'm working on a project that produces sound through button combinations. I felt the need of having to debounce my module because there are times that the reading is inconsistent but the problem is I don't know how to debounce it when it comes to multiple buttons. Can you guys please help me?
Here is my code:
#include "pitches.h"
int swiPin [] = {23,24,25,26,27,28,29};
int speakerPin = 8;
//Grouping of combinations
int groupA;
void setup(){
for(int x = 0; x<7; x++){
pinMode(swiPin[x], INPUT);
pinMode(swiPin2[x], INPUT);
//digitalWrite(swiPin[x], 1);
//digitalWrite(swiPin2[x], 1);
}
for(int x = 0; x<2; x++){
pinMode(swiPin3[x], INPUT);
//digitalWrite(swiPin3[x], 1);
}
Serial.begin(9600);
}
void check_fingering(){
//Check keys pressed
groupA = 1*(digitalRead(swiPin[0])) + 2*(digitalRead(swiPin[1])) + 4*(digitalRead(swiPin[2])) + 8*(digitalRead(swiPin[3]));
}
void loop(){
check_fingering();
if (groupA == 1){
Serial.println("Button 1 is pressed");
tone(speakerPin, NOTE_C4 );
}
else if (groupA == 2){
Serial.println("Button 2 is pressed");
tone(speakerPin, NOTE_D4);
}
else if (groupA == 4){
Serial.println("Button 3 is pressed");
tone(speakerPin, NOTE_E4);
}
else if (groupA == 3){
Serial.println("Button 1 and 2 is pressed");
tone(speakerPin, NOTE_G4);
}
else if (groupA == 5){
Serial.println("Button 1 and 3 is pressed");
tone(speakerPin, NOTE_A4);
}
else if (groupA == 6){
Serial.println("Button 2 and 3 is pressed");
tone(speakerPin, NOTE_B4);
}
else if (groupA == 7){
Serial.println("Button 1 and 2 and 3 is pressed");
tone(speakerPin, NOTE_C5);
}
else if (groupA == 8){
Serial.println("Button 4 is pressed");
tone(speakerPin, NOTE_F4);
}
else if (groupA == 9){
Serial.println("Button 4 and 1 is pressed");
tone(speakerPin, NOTE_C3);
}
else if (groupA == 10){
Serial.println("Button 4 and 2 is pressed");
tone(speakerPin, NOTE_D3);
}
else if (groupA == 11){
Serial.println("Button 4 and 2 and 1 is pressed");
tone(speakerPin, NOTE_E3);
}
else if (groupA == 12){
Serial.println("Button 4 and 3 is pressed");
tone(speakerPin, NOTE_F3);
}
else if (groupA == 13){
Serial.println("Button 4 and 3 and 1 is pressed");
tone(speakerPin, NOTE_G3);
}
else if (groupA == 14){
Serial.println("Button 4 and 3 and 2 is pressed");
tone(speakerPin, NOTE_A3);
}
else if (groupA == 15){
Serial.println("Button everything is pressed");
tone(speakerPin, NOTE_B3);
}
else{
noTone(speakerPin);
}
//delay(500);
}