First Project Question (Keyboard)

Hello everyone! I’ve coded in C++ in the past but this is my first Arduino project! This project is a simple keyboard, I have everything for that wired up and working properly. I also want to be able to record the notes played, and that’s where I’m running into trouble. Right now if a button is pressed (providing 5v to pin 7) the current note is added to a vector. if a second button is pressed it plays the notes in the vector then clears it out. For some reason I’m not seeing any response from pushing buttons for pin 7 and 9. All the others I can see on the serial monitor. I know it’s impossible for you to try and diagnose the circuit but as long as I duplicated the setup for the note buttons I should see it in the serial monitor right? Any help is appreciated, here is the code:

#include <StandardCplusplus.h>
#include <system_configuration.h>
#include <unwind-cxx.h>
#include <utility.h>
#include <vector>

using namespace std;
//Assigning notes to input pins
int gNote = 2; 
int fNote = 3; 
int eNote = 4; 
int dNote = 5; 
int cNote = 6;
//Designating record pin
int record = 7;
//Designating output pin
int outputPin = 8;
//Designating playback pin
int play = 9;
int note;
vector<int> playBack;

//Array of frequencies for each note
int toneNotes[] = { 1915, 1700, 1519, 1432, 1275};

void setup(void) {
  pinMode(gNote, INPUT);
  pinMode(fNote, INPUT);
  pinMode(eNote, INPUT);
  pinMode(dNote, INPUT);
  pinMode(cNote, INPUT);
  pinMode(record, INPUT);
  pinMode(play, INPUT);
  Serial.begin(9600);   // Sends debugging information via the Serial monitor
}

void loop(void)
{
  note = -1;

  //Tests input voltage of a pin assingns a note
  if(digitalRead(gNote)== HIGH)
  {
    note = 4;
  }
  
  if(digitalRead(fNote)== HIGH)
  {
    note = 3;
  }
  
  if(digitalRead(eNote)== HIGH)
  {
    note = 2;
  }
  
  if(digitalRead(dNote)== HIGH)
  {
    note = 1;
  }
  
  if(digitalRead(cNote)== HIGH)
  {
    note = 0;
  }
  
  //If record button is pressed add note to vector 
  if(digitalRead(record)== HIGH && note > -1)
  {
    playBack.push_back(toneNotes[note]);
  }

  //Debugging Output
  Serial.print("Digital reading = ");
  Serial.println(note);

  //Output note for button pressed
  if(note > -1)
  {
    tone(outputPin, toneNotes[note],250);
  }

  //Playback recorded notes
  if (digitalRead(play)== HIGH)
  {
    for (int i =0; i < playBack.size(); i++)
    {
      tone(outputPin, toneNotes[playBack[i]],250);
      delay(10);
    }
    playBack.clear();
  }
}

Well, according to the code, pressing pin 7 or pin 9 doesn't change Note, so yeah that won't get printed out. Also, it looks like pressing pin 7 doesn't do anything unless some other note is pressed. Pressing pin 9 doesn't do anything unless something has been recorded.

Try holding down the record key while you play other notes, and see if that works. THEN press replay.

How are your input pins wired? Do you have pulldown resistors? What value?

Interesting that you can use vector. I would have expected it to gobble up all the memory.

#include <StandardCplusplus.h>
#include <system_configuration.h>
#include <unwind-cxx.h>
#include <utility.h>
#include <vector>

using namespace std;

The WTF light exploded.

vaj4088 I'm using pulldown resistors all are 220K. PaulS not sure what that means, lol. All of the includes are just so I can use a vector, is there a simpler way? Thanks, for the feedback everyone!

All of the includes are just so I can use a vector

And you need a vector because?

In record mode, you are pushing things onto a queue. In playback mode, you are playing the notes in the queue.

The use of the vector class limits the number of notes you can enqueue, due to the amount of overhead involved in creating the required nodes in the doubly-linked list.

You could use an array that has room for more notes because you are not wrapping ints in nodes in a doubly-linked list.

No need to push anything. Just store the note in the next position in the array.

Playback is even easier. Just play the notes in order.