BY BENNA SU
This is the video!
For the serial monitor somehow it does not work but I wrote all the code.
Here is the code!
int LedRedPin = 7;
int LedYellowPin = 8;
int LedBluePin = 9;
int LedGreenPin = 10;
int Button1 = 33;
int Button2 = 34;
int Button3 = 35;
int Button4 = 36;
int mappedPotVal = 0;
int potvalue = 0;
int lastpotvalue = 0;
int lastCCval = 0;
int ccval = 0;
bool lastButtonState = LOW;
bool buttonState = LOW;
void setup() {
Serial.begin(9600);
pinMode(LedRedPin, OUTPUT);
pinMode(LedYellowPin, OUTPUT);
pinMode(LedBluePin, OUTPUT);
pinMode(LedGreenPin, OUTPUT);
pinMode(Button1, INPUT);
pinMode(Button2, INPUT);
pinMode(Button3, INPUT);
pinMode(Button4, INPUT);
// put your setup code here, to run once:
}
void loop() {
Buttoncheck1();
Buttoncheck2();
Buttoncheck3();
Buttoncheck4();
mapped();
// put your main code here, to run repeatedly:
}
void Buttoncheck1() {
lastButtonState = buttonState;
buttonState = digitalRead(Button1);
if (lastButtonState == LOW and buttonState == HIGH) {
usbMIDI.sendNoteOn(60, 127, 1);
delay(5);
} else if (lastButtonState == HIGH and buttonState == LOW) {
usbMIDI.sendNoteOff(60, 0, 1);
delay(5);
}
}
void Buttoncheck2() {
lastButtonState = buttonState;
buttonState = digitalRead(Button2);
if (lastButtonState == LOW and buttonState == HIGH) {
usbMIDI.sendNoteOn(64, 127, 1);
delay(5);
} else if (lastButtonState == HIGH and buttonState == LOW) {
usbMIDI.sendNoteOff(64, 0, 1);
delay(5);
}
}
void Buttoncheck3() {
lastButtonState = buttonState;
buttonState = digitalRead(Button3);
if (lastButtonState == LOW and buttonState == HIGH) {
usbMIDI.sendNoteOn(68, 127, 1);
delay(5);
} else if (lastButtonState == HIGH and buttonState == LOW) {
usbMIDI.sendNoteOff(68, 0, 1);
delay(5);
}
}
void Buttoncheck4() {
lastButtonState = buttonState;
buttonState = digitalRead(Button4);
if (lastButtonState == LOW and buttonState == HIGH) {
usbMIDI.sendNoteOn(72, 127, 1);
delay(5);
} else if (lastButtonState == HIGH and buttonState == LOW) {
usbMIDI.sendNoteOff(72, 0, 1);
delay(5);
}
}
void mapped() {
usbMIDI.read();
lastCCval = ccval;
ccval = analogRead(potvalue) / 8;
if (ccval != lastCCval) {
usbMIDI.sendControlChange(0, ccval, 1);
}
lastpotvalue = potvalue;
potvalue = analogRead(A13);
mappedPotVal = map(potvalue, 0, 1023, 10, 20);
Serial.println(potvalue);
}