Hello, everybody. I'm new here. I wrote some pretty bad code, and had ChatGPT improve it. Here is the current code:
#include <MIDI.h> // Add Midi Library
#include <Wire.h> // Add library allows to communicate with I2C devices
#include <Adafruit_PWMServoDriver.h> // Add 16-channel PWM & Servo driver library
#define SERVOMIN 200
#define SERVOMAX 400
#define FREQUENCY 50
Adafruit_PWMServoDriver pwm = Adafruit_PWMServoDriver();
MIDI_CREATE_DEFAULT_INSTANCE();
// Function Declarations
void NoteOn(byte channel, byte pitch, byte velocity);
void NoteOff(byte channel, byte pitch, byte velocity);
void setup() {
pwm.begin();
pwm.setPWMFreq(FREQUENCY);
MIDI.begin(MIDI_CHANNEL_OMNI);
Serial.begin(115200);
MIDI.turnThruOff();
MIDI.setHandleNoteOn(NoteOn);
MIDI.setHandleNoteOff(NoteOff);
}
void loop() {
// Your code here
}
// move servos - note on
void NoteOn(byte channel, byte pitch, byte velocity) {
if (channel == 0) { // MIDI channel 1
switch (pitch) {
case 60: pwm.setPWM(1, 0, SERVOMAX); break;
case 61: pwm.setPWM(2, 0, SERVOMAX); break;
case 62: pwm.setPWM(3, 0, SERVOMAX); break;
case 63: pwm.setPWM(4, 0, SERVOMAX); break;
case 64: pwm.setPWM(5, 0, SERVOMAX); break;
case 65: pwm.setPWM(6, 0, SERVOMAX); break;
case 66: pwm.setPWM(7, 0, SERVOMAX); break;
case 67: pwm.setPWM(8, 0, SERVOMAX); break;
case 68: pwm.setPWM(9, 0, SERVOMAX); break;
case 69: pwm.setPWM(10, 0, SERVOMAX); break;
default: break; // Handle other pitches if needed
}
}
}
// move servos - note off
void NoteOff(byte channel, byte pitch, byte velocity) {
if (channel == 0) { // MIDI channel 1
switch (pitch) {
case 60: pwm.setPWM(1, 0, SERVOMIN); break;
case 61: pwm.setPWM(2, 0, SERVOMIN); break;
case 62: pwm.setPWM(3, 0, SERVOMIN); break;
case 63: pwm.setPWM(4, 0, SERVOMIN); break;
case 64: pwm.setPWM(5, 0, SERVOMIN); break;
case 65: pwm.setPWM(6, 0, SERVOMIN); break;
case 66: pwm.setPWM(7, 0, SERVOMIN); break;
case 67: pwm.setPWM(8, 0, SERVOMIN); break;
case 68: pwm.setPWM(9, 0, SERVOMIN); break;
case 69: pwm.setPWM(10, 0, SERVOMIN); break;
default: break; // Handle other pitches if needed
}
}
}
I keep changing my methods. Currently, I'm using a program called Noteur to play the MIDI files. Note, I am VERY new to this stuff. My hardware is as follows: Arduino Uno, PCA9685, Correct wiring, 10 servos total, a pipe organ base (holds micro servos) - 8 notes (1 servo per note) - 3d printed to control organ pipes using valves that uncover and cover pipe feet, 2 3d printed drum mallets on stands, controlled by micro servos.
I cannot fine-tune all of the servo positions because of my main problem: No matter what program I use, COM5 (my current Arduino USB PC end port). I have all the required libraries. (MIDI is FourtySevenEffects' library). If anybody can help with either the code or the MIDI mapping problem, please let me know. I would really appreciate it!