Just received my uno today and have started on my first project, a simple midi controller.
Now I’ve seen a few options/ examples around and am looking for some advice on which is best. Basically I’m looking to start with a simple push button program change midi controller.
This one is very basic, with the bush button linked to ground via 10k resister until a button push puts +5v on the assigned pins. Programming req is minimal.
Alternatively, the notes and volts design is based around grounding the assigned pin via the button. Programming seems a lot more complicated but includes pots and multiplexer which I’m not bothered about.
Both will need some tweaking to get to where a I want but Is there a right or wrong way, ultimately I’m looking at a 8 button program controller which I can add features to as I learn more.
seems you have a good link to a tutorial... go with it.
after the first tutorial you will have a good idea of how and how well these things work and how much more you might want to add.
Using INPUT_PULLUP and grounding the pin is the preferred way of dealing with pushbuttons (saves buying extra resistors and finding somewhere to fit them). But would be easy to change the first code to use that method so I'd probably start with that.
Personally, I wouldn't waste too much time with the notes and volts code, it's messy and contains a lot of bad and confusing practices, like the arrays of pointers.
What it does do correctly is using the internal pull-up resistors as mentioned by slipstick.
If you want a simple and extensible program change controller, I can recommend the Control Surface library I'm working on.
With the first one, you just create some PCButtons that read the button state from the given pin, and send out a MIDI Program Change event for the given program and MIDI channel when pressed.
If you need to add more buttons, just add more PCButtons in the code (you can create an array of them). You can also enter the program number instead of the program name if you want to.
[color=#5e6d03]#include[/color] [color=#434f54]<[/color][b][color=#d35400]Control_Surface[/color][/b][color=#434f54].[/color][color=#000000]h[/color][color=#434f54]>[/color] [color=#434f54]// Include the Control Surface library[/color]
[color=#434f54]// Instantiate a MIDI over USB interface that will be used by Control Surface[/color]
[b][color=#d35400]USBMIDI_Interface[/color][/b] [color=#00979c]midi[/color][color=#000000];[/color]
[color=#434f54]// Instantiate a PCButton that reads the input from a push button and sends out [/color]
[color=#434f54]// a MIDI Program Change message when it's pressed.[/color]
[b][color=#d35400]PCButton[/color][/b] [color=#000000]pcBtn[/color] [color=#434f54]=[/color] [color=#000000]{[/color]
[color=#000000]2[/color][color=#434f54],[/color] [color=#434f54]// pin[/color]
[color=#000000]{[/color][b][color=#d35400]MIDI_PC[/color][/b][color=#434f54]:[/color][color=#434f54]:[/color][color=#00979c]Steel_Drums[/color][color=#434f54],[/color] [color=#00979c]CHANNEL_1[/color][color=#000000]}[/color][color=#434f54],[/color] [color=#434f54]// address[/color]
[color=#000000]}[/color][color=#000000];[/color]
[color=#00979c]void[/color] [color=#5e6d03]setup[/color][color=#000000]([/color][color=#000000])[/color] [color=#000000]{[/color]
[b][color=#d35400]Control_Surface[/color][/b][color=#434f54].[/color][color=#d35400]begin[/color][color=#000000]([/color][color=#000000])[/color][color=#000000];[/color] [color=#434f54]// Initialize Control Surface[/color]
[color=#000000]}[/color]
[color=#00979c]void[/color] [color=#5e6d03]loop[/color][color=#000000]([/color][color=#000000])[/color] [color=#000000]{[/color]
[b][color=#d35400]Control_Surface[/color][/b][color=#434f54].[/color][color=#5e6d03]loop[/color][color=#000000]([/color][color=#000000])[/color][color=#000000];[/color] [color=#434f54]// Update the Control Surface[/color]
[color=#000000]}[/color]
thanks for all the advice so far, am really quite confused as there's so many different ways of doing this.
Was starting with the very basics like pin assignment, reading about the Input_Pullup, how it works etc, then looking at some basic tutorial examples to develop some understanding.
Looking at the examples Pieter kindly posted, i see there's alternative code that automates some of the basic functions, for example PCButton takes care of Input_Pullup, debounce and send midi program change events - making the code very tidy but probably too big a step for me.
So i'm going to start from scratch and keep plugging away with tutorials and put something very basic together
One question, Pieters example uses the Control Surface Library whereas i have a standalone DMX controller with a midi input, will that work or do i need to use the midi library and ammend any code - would like to see it working
in particular, how would i change this so i can send the midi parameter 127 (which is blackout on my controller) on channel 1
// Instantiate a PCButton that reads the input from a push button and sends out
// a MIDI Program Change message when it's pressed.
PCButton pcBtn = {
2, // pin
{MIDI_PC::Steel_Drums, CHANNEL_1}, // address
};
Control Surface comes with many different MIDI Interfaces.
If you want to use the usual 5-pin DIN MIDI connection instead of MIDI over USB, you can use something like this:
[color=#5e6d03]#include[/color] [color=#434f54]<[/color][b][color=#d35400]Control_Surface[/color][/b][color=#434f54].[/color][color=#000000]h[/color][color=#434f54]>[/color] [color=#434f54]// Include the Control Surface library[/color]
[color=#434f54]// Instantiate a Serial MIDI interface that will be used by Control Surface[/color]
[b][color=#d35400]HardwareSerialMIDI_Interface[/color][/b] [color=#00979c]midi[/color] [color=#434f54]=[/color] [color=#000000]{[/color][b][color=#d35400]Serial[/color][/b][color=#434f54],[/color] [color=#00979c]MIDI_BAUD[/color][color=#000000]}[/color][color=#000000];[/color]
[color=#434f54]// Instantiate a PCButton that reads the input from a push button and sends out [/color]
[color=#434f54]// a MIDI Program Change message when it's pressed.[/color]
[b][color=#d35400]PCButton[/color][/b] [color=#000000]pcBtn[/color] [color=#434f54]=[/color] [color=#000000]{[/color]
[color=#000000]2[/color][color=#434f54],[/color] [color=#434f54]// pin[/color]
[color=#000000]{[/color][color=#000000]127[/color][color=#434f54],[/color] [color=#00979c]CHANNEL_1[/color][color=#000000]}[/color][color=#434f54],[/color] [color=#434f54]// address: program change #127 on MIDI Channel 1[/color]
[color=#000000]}[/color][color=#000000];[/color]
[color=#00979c]void[/color] [color=#5e6d03]setup[/color][color=#000000]([/color][color=#000000])[/color] [color=#000000]{[/color]
[b][color=#d35400]Control_Surface[/color][/b][color=#434f54].[/color][color=#d35400]begin[/color][color=#000000]([/color][color=#000000])[/color][color=#000000];[/color] [color=#434f54]// Initialize Control Surface[/color]
[color=#000000]}[/color]
[color=#00979c]void[/color] [color=#5e6d03]loop[/color][color=#000000]([/color][color=#000000])[/color] [color=#000000]{[/color]
[b][color=#d35400]Control_Surface[/color][/b][color=#434f54].[/color][color=#5e6d03]loop[/color][color=#000000]([/color][color=#000000])[/color][color=#000000];[/color] [color=#434f54]// Update the Control Surface[/color]
[color=#000000]}[/color]
This way, it's very similar to the MIDI library.
I also changed the MIDI program to #127 instead of "steel drums".
I kind of steamed ahead and hooked up my DMX controller only to find it didn't work. I don't have a midi to usb device here so wasn't sure what was the weak link.
I have now found some additional information on my controller which isn't in the manual. Apparently the controller only responds to midi when in auto mode but also only responds to note on and note off data rather than CC or PC commands.
I've googled around for some simple sketches that may test to see if this is the case and did have a tiny instance of success when the scene changed from 8 to 1, nothing else happened after that, which was probably due to an out of date sketch, and my inexperience/tinkering.
Success! So...am making some progress after literally finding a weak link on my ebay breadboard. Basic prototype is up and running so it's hardware time. Have currently got 8 inputs, controlling 8 different elements on my DMX controller.
Sadly my current controller is very basic so am quite limited to what it can do but with some tweaking of how i program it, I should be able to deliver something half decent ...However, i do have a software based DMX system which is far more versatile so that could be an interesting step up.
A sincere thank you for the input to date..much appreciated!