Simple Midi cc send with a botten ?? Help.

Hi im new in this! very new. :astonished:
Ive viewed looked at many sketches from the internet, many of them are overwhelming and too much anve very impressing..
I also tryed to look at the Midi reference, but i just can figure out how to put the sketch together.

all the midi is a riddle for me!!

What i would like to do is, press a botton and send a midi cc "command"

im with so far:

int buttonPin = 2;

void setup() {
void loop ()
if (buttonState == HIGH) {


and thats it, i know that this not is rocket science, but im finding it hard to understand.

the history behind this is that i would like a extra botten to control my guitar pedal ( a Boss GT-10 ) and within the i pedal i can activate "like an fx" if it reciewe a midi cc ( called CC#1 to 31 or 64 to 95 )

so if i can make the a botton send a midi cc command when pressed it would be great..

is this it??? exept the baud rate?

void setup() {
Serial.begin(57600); // open serial port

void loop() {

Serial.print(0xB2, BYTE); // MIDI control change; channel 3
Serial.print(1, BYTE); // MIDI controller #1
Serial.print(127, BYTE); // MIDI controller value of 127


You don't want to send the CC message every time you detect the input to be high, so you need to only do this when you detect the switch gong from inactive state to active state (called "edge detection").

The last code you supplied does not use a switch at all?

Thats right.

Just before i went to bed i found the cc code, i think?

But yes. When the botten is pressed i would like to send the midi data. And it well send again when i press the botten again.


UHU!!! I got some life ( or communication ) or, this is a BIG step for me !!!!

i tryed this code, and are now avaible to use a pot to send the midi cc

byte val = 0;

void setup() {

void loop() {
val = analogRead(0) / 8;

Serial.print(0xB0, BYTE); // MIDI control change; channel 1
Serial.print(1, BYTE); // CC#1
Serial.print(val, BYTE); // MIDI controller value from potentiometer 1

but, i still need to get my botton to work with it ? du i change the val to a number ? and why does the sketch starts with " byte val = 0 " ??

Wrap the code to send the MIDI message in an if statement

if button is pressed
send midi message

Clearly you will need to write actual code, but that is the basic logic. If you are comfortable writing a function that returns true or false if the button edge has been detected, it is neater to wrap up the code in that sort of construct. Otherwise just write it inline in loop().

That code will not even compile using the latest Arduino IDE replace

Serial.print(0xB0, BYTE); // MIDI control change; channel 1 
Serial.write(0xB0); // MIDI control change; channel 1

The same for the other two print statements.

Real the how to use the forum sticky to find out how to post code.
Look at the examples menu in the IDE for the basics of programming, they are simple examples.

Oh yes, i didnt mention that im using ide version 0023, with the newer version wont eat the BYTE command