Compare commits

...

2 Commits

Author SHA1 Message Date
6381038c8e Additional midi note state 2024-01-22 15:39:15 +01:00
e1ca9dc92f Correct naming
Co-authored-by: Oliver Parczyk <oliver.parczyk@mailbox.tu-dresden.de>
2024-01-22 15:23:02 +01:00
2 changed files with 23 additions and 6 deletions

View File

@ -1,8 +1,5 @@
#include <Arduino.h>
#define MIDI_NAME {'P', 'i', 'n', 'g', 'b', 'o', 'a', 'r', 'd'}
#define MIDI_NAME_LEN 9
#define KEY_GROUP_NUM 9
#define KEY_PINS 6
#define NUMBER_OF_KEYS 49
@ -17,6 +14,8 @@ const uint8_t group_pins[KEY_GROUP_NUM] {14, 15, 16, 17, 18, 19, 20, 21, 22};
const uint8_t key_pins[KEY_PINS] {2, 3, 4, 5, 6, 7};
// Array of pressed keys (initially all 0)
uint8_t keys_pressed[NUMBER_OF_KEYS];
// Array of currently active midi notes
bool active_notes[NUMBER_OF_KEYS];
// K1, K2, K3, K4, K5, K12, K13, K14, K15
const uint8_t self_drive_pins[KEY_GROUP_NUM] {8, 9, 10, 11, 12, 26, 23, 24, 25};
uint8_t current_self_drive_pin = 0;
@ -72,8 +71,9 @@ int8_t getActiveKeyGroup() {
// Set the next self drive pin
FASTRUN void nextSelfDrivePin() {
// Set the current pin to high
// Set previous pin to low
digitalWriteFast(self_drive_pins[current_self_drive_pin != 0 ? current_self_drive_pin - 1 : KEY_GROUP_NUM - 1], LOW);
// Set the current pin to high
digitalWriteFast(self_drive_pins[current_self_drive_pin], HIGH);
// Set the next pin
current_self_drive_pin = (current_self_drive_pin + 1) % KEY_GROUP_NUM;
@ -114,7 +114,9 @@ void loop() {
// ! inverted
if (value == LOW) {
// Check if the key is not already pressed
if (keys_pressed[active_key_group * 6 + i] >= DEBOUNCE_TIMES) {
if (keys_pressed[active_key_group * 6 + i] >= DEBOUNCE_TIMES && !active_notes[active_key_group * 6 + i]) {
// Note is on
active_notes[active_key_group * 6 + i] = true;
// Send MIDI message
usbMIDI.sendNoteOn(mapToMidi(active_key_group, i), 127, 1);
}
@ -123,7 +125,9 @@ void loop() {
keys_pressed[active_key_group * 6 + i] += keys_pressed[active_key_group * 6 + i] < 0xFF ? 1 : 0;
} else {
// Check if the key is not already released
if (keys_pressed[active_key_group * 6 + i] < DEBOUNCE_TIMES) {
if (keys_pressed[active_key_group * 6 + i] < DEBOUNCE_TIMES && active_notes[active_key_group * 6 + i]) {
// Note is off
active_notes[active_key_group * 6 + i] = false;
// Send MIDI message
usbMIDI.sendNoteOff(mapToMidi(active_key_group, i), 0, 1);
}

13
src/name.c Normal file
View File

@ -0,0 +1,13 @@
// To give your USB MIDI device a unique name, this code must be placed into a .c file (its own tab). It can not be in a .cpp file or your main sketch (the .ino file).
#include "usb_names.h"
// Edit these lines to create your own name. The length must match the number of characters in your custom name.
#define MIDI_NAME {'P', 'i', 'n', 'g', 'b', 'o', 'a', 'r', 'd'}
#define MIDI_NAME_LEN 9
// Do not change this part. This exact format is required by USB.
struct usb_string_descriptor_struct usb_string_product_name = {
2 + MIDI_NAME_LEN * 2,
3,
MIDI_NAME
};