Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Programmed for Inland Arduino Nano clone, Microcenter Inland Nano requires bootloader set to ATmega328p (old bootloader)
- // Functional on typical Arduino Nano
- // Ported from PJRC Teensy 4.1
- #include <digitalWriteFast.h> // Include library for fast digital read/writes (requires download through Library Manager)
- const int buttonPin = 2; // Set button pin to pin 2
- int lastState = HIGH; // Set "last button state" for first loop() comparison
- int currentState; // Declare "current button state" variable
- const byte midiChannel = 0; // 0 = Channel 1
- const byte ccNumber = 18; // BUS1 FX3 is CC#18
- void sendMIDI_CC(byte controlNumber, byte value) {
- byte status = 0xB0 | (midiChannel & 0x0F); // 0xB0 = Control Change on channel 1
- Serial.write(status);
- Serial.write(controlNumber); // Write CC number
- Serial.write(value); // Write CC value
- }
- void setup() {
- pinMode(buttonPin, INPUT_PULLUP); // Setup button pin
- Serial.begin(31250); // MIDI baud rate
- }
- void loop() {
- currentState = digitalReadFast(buttonPin);
- if (currentState != lastState) {
- delay(5); // debounce code to prevent flooding MIDI commands from an iffy switch
- currentState = digitalReadFast(buttonPin);
- if (currentState != lastState) {
- if (currentState == LOW) {
- sendMIDI_CC(ccNumber, 127); // Button pressed
- } else {
- sendMIDI_CC(ccNumber, 0); // Button released
- }
- lastState = currentState; // Reset button state
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement