mirror of
https://github.com/C0ntroller/keyboard.git
synced 2024-11-21 22:14:49 +01:00
Compare commits
No commits in common. "6381038c8efc931cb11c8afc8ed0744e4bd9ab65" and "2cd7817d5c38348732ed8b2211cd223be1f953ce" have entirely different histories.
6381038c8e
...
2cd7817d5c
16
src/main.cpp
16
src/main.cpp
@ -1,5 +1,8 @@
|
||||
#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
|
||||
@ -14,8 +17,6 @@ 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;
|
||||
@ -71,9 +72,8 @@ int8_t getActiveKeyGroup() {
|
||||
|
||||
// Set the next self drive pin
|
||||
FASTRUN void nextSelfDrivePin() {
|
||||
// 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 != 0 ? current_self_drive_pin - 1 : KEY_GROUP_NUM - 1], LOW);
|
||||
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,9 +114,7 @@ void loop() {
|
||||
// ! inverted
|
||||
if (value == LOW) {
|
||||
// Check if the key is not already pressed
|
||||
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;
|
||||
if (keys_pressed[active_key_group * 6 + i] >= DEBOUNCE_TIMES) {
|
||||
// Send MIDI message
|
||||
usbMIDI.sendNoteOn(mapToMidi(active_key_group, i), 127, 1);
|
||||
}
|
||||
@ -125,9 +123,7 @@ 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 && active_notes[active_key_group * 6 + i]) {
|
||||
// Note is off
|
||||
active_notes[active_key_group * 6 + i] = false;
|
||||
if (keys_pressed[active_key_group * 6 + i] < DEBOUNCE_TIMES) {
|
||||
// Send MIDI message
|
||||
usbMIDI.sendNoteOff(mapToMidi(active_key_group, i), 0, 1);
|
||||
}
|
||||
|
13
src/name.c
13
src/name.c
@ -1,13 +0,0 @@
|
||||
// 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
|
||||
};
|
Loading…
Reference in New Issue
Block a user