Noise Makers
Description
Video Demonstration
Photos
Sketch
Schematic
Code
/*
* MIDIUSB_test.ino
*
* Created: 4/6/2015 10:47:08 AM
* Author: gurbrinder grewal
* Modified by Arduino LLC (2015)
*/
#include "MIDIUSB.h"
// First parameter is the event type (0x09 = note on, 0x08 = note off).
// Second parameter is note-on/note-off, combined with the channel.
// Channel can be anything between 0-15. Typically reported to the user as 1-16.
// Third parameter is the note number (48 = middle C).
// Fourth parameter is the velocity (64 = normal, 127 = fastest).
void noteOn(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOn = {0x09, 0x90 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOn);
}
void noteOff(byte channel, byte pitch, byte velocity) {
midiEventPacket_t noteOff = {0x08, 0x80 | channel, pitch, velocity};
MidiUSB.sendMIDI(noteOff);
}
int btn1 = 9;
int btn2 = 10;
int btn3 = 11;
const int knobPin = A0;
void setup() {
Serial.begin(115200);
pinMode(btn1, INPUT_PULLUP);
pinMode(btn2, INPUT_PULLUP);
pinMode(btn3, INPUT_PULLUP);
}
// First parameter is the event type (0x0B = control change).
// Second parameter is the event type, combined with the channel.
// Third parameter is the control number number (0-119).
// Fourth parameter is the control value (0-127).
void controlChange(byte channel, byte control, byte value) {
midiEventPacket_t event = {0x0B, 0xB0 | channel, control, value};
MidiUSB.sendMIDI(event);
}
void loop() {
int knob = analogRead(knobPin);
int note1 = map(knob, 0, 1023, 48, 72); // 1 octave is 12 consecutive semitones so this will go from C3 which is 48 to 72 which is C5
int note2 = map(knob, 0, 1023, 50, 74);
int note3 = map(knob, 0, 1023, 52, 76);
// note 1
if(digitalRead(btn1) == LOW){
noteOn(0, note1, 64); // Channel 0, middle C, normal velocity
Serial.println("Sending note on");
}
if(digitalRead(btn1) == HIGH){
noteOff(0, note1, 64); // Channel 0, middle C, normal velocity
Serial.println("Sending note on");
}
MidiUSB.flush();
// note 2
if(digitalRead(btn2) == LOW){
noteOn(0, note2, 64); // Channel 0, middle C, normal velocity
Serial.println("Sending note on");
}
if(digitalRead(btn2) == HIGH){
noteOff(0, note2, 64); // Channel 0, middle C, normal velocity
Serial.println("Sending note on");
}
MidiUSB.flush();
// note 3
if(digitalRead(btn3) == LOW){
noteOn(0, note3, 64); // Channel 0, middle C, normal velocity
Serial.println("Sending note on");
}
if(digitalRead(btn3) == HIGH){
noteOff(0, note3, 64); // Channel 0, middle C, normal velocity
Serial.println("Sending note on");
}
MidiUSB.flush();
}




No comments:
Post a Comment
Note: Only a member of this blog may post a comment.