I wrote a script below to read digital signals from my new Adafruit Grand Central, and once it is working these signals will be translated to MIDI signals so I can add MIDI USB output to my acoustic piano. My first step was debugging using the Serial Monitor to make sure all the digital and analog pins do what I expect, which is to turn from HIGH to LOW if I connect them to ground.
The issues I am having:
1. pin 13 is stuck on LOW whether connected to ground or not
2. Instead of analog pins A0-A15 being labeled 54-70 (expected behavior), I am getting A0-A3 being accessible in my script as pins 62-66, A8-A15 as 54-61, and it appears A4-A7 (62-66?) don't change from HIGH to LOW no matter what I do. Therefore I am unable to change the state from HIGH to LOW on A4-A7 using this script, and the Analog pin assignments seem...weird.
Are my issues the fault of the board, my script, the Arduino IDE (using the version 1.8.15 tarball directly in Debian), or the board manager (I followed instructions at https://learn.adafruit.com/adafruit-ard ... ot-6-x-ide)?
Thanks, and sorry if I am posting any of this incorrectly.
Code: Select all
#if 0
// Final script will use this library to turn microcontroller into MIDI USB device.
// Script assumes use of Arduino Due or Adafruit Grand Central
// When debugging using the Serial Monitor, pin 13 is always LOW, 67-70 are labeled "A0-A3", 62-66 (A4-A7?) don't go to LOW at all, 54-61 are labeled A8-A15.
#include <MIDIUSB.h>
#endif
// KEY_QTY starts at 0, ie "3" would mean 4 total keys.
// For final script this will be = 70.
const byte KEY_QTY = 68;
// Temporary and allows for easier Serial debugging
const byte PIN_OFFSET = 2;
//Initializing
byte key_states[KEY_QTY]; // using an array for comparing MIDI states comes from https://www.instructables.com/Building-an-Arduino-MIDI-Controller/
byte key_state;
void setup() {
Serial.begin(9600); // This line for debugging, not final script.
for (byte i = 0; i <= KEY_QTY; i++) {
byte pin = i + PIN_OFFSET;
pinMode(pin, INPUT_PULLUP);
}
}
void loop() {
for (byte i = 0; i <= KEY_QTY; i++) {
delay(200); // This will be 1 or 2 for final script. 200 is handier for Serial debugging.
byte pin = i + PIN_OFFSET;
byte key_state = digitalRead(pin);
// The following Serial.print lines for debugging, not final script.
Serial.print(key_state);
Serial.print("\t");
Serial.print(pin);
Serial.print("\n");
#if 0
// This block for final script
if (key_state != key_states[i]) {
key_states[i] = key_state;
byte pitch = i+25;
if (key_state == LOW) {
key_pressed(note);
} else {
key_released(note);
}
}
#endif
}
}
#if 0
// This block for final script. Sends MIDI signal to PC.
void key_pressed(byte note) {
MidiUSB.sendMIDI({0x09, 0x90, pitch, 64});
MidiUSB.flush();
}
void key_released(byte note) {
MidiUSB.sendMIDI({0x08, 0x80, pitch, 0});
MidiUSB.flush();
}
#endif