Hey all, Im totally new to programming, so i assume there is some small formatting error i am committing, but i cant figure out what it is.
I am taking 2 working programs and trying to combine in to 1.
I am trying to set up a Recording Light that will turn on when I start recording audio in Logic Pro on my mac. The goal is to make a device that will listen to a MIDI channel and turn on the light when the tone is sent, this part works with this method:
and the code for the MIDI input test program found here:
that works fairly well so far, but now i want to add a button to just turn the light on manually when i want as well.. Like a manual override switch. so i am trying to add the program from the examples; 02.digital: Button
I have tried an number of ways but i can get past the error message:
'MyHandleNoteOn' was not declared in this scope
but i dont think i have changed anything too cause this to no longer work its seems like just a formating thing.
Here is my most recent attempt to combine these, i would really appreciate if someone could tell me where i am going wrong.
#include <MIDI.h> // Add Midi Library
int LED = 13; // Arduino Board LED is on Pin 13
int buttonPin = 2;
int buttonState = 0;
//Create an instance of the library with default name, serial port and settings
MIDI_CREATE_DEFAULT_INSTANCE();
void setup() {
pinMode (LED, OUTPUT); // Set Arduino board pin 13 to output
pinMode (buttonPin, INPUT);
MIDI.begin(2); // Initialize the Midi Library.
// OMNI sets it to listen to all channels.. MIDI.begin(2) would set it
// to respond to notes on channel 2 only.
MIDI.setHandleNoteOn(MyHandleNoteOn); // This is important!! This command
// tells the Midi Library which function you want to call when a NOTE ON command
// is received. In this case it's "MyHandleNoteOn".
MIDI.setHandleNoteOff (MyHandleNoteOff); // This command tells the Midi Library
// to call "MyHandleNoteOff" when a NOTE OFF command is received.
}
void loop()
{ // Main loop
MIDI.read(); // Continuously check if Midi data has been received.
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(LED, HIGH);
} else {
// MyHandleNoteON is the function that will be called by the Midi Library
// when a MIDI NOTE ON message is received.
// It will be passed bytes for Channel, Pitch, and Velocity
void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
digitalWrite(LED,HIGH); //Turn LED on
}
// MyHandleNoteOFF is the function that will be called by the Midi Library
// when a MIDI NOTE OFF message is received.
// * A NOTE ON message with Velocity = 0 will be treated as a NOTE OFF message *
// It will be passed bytes for Channel, Pitch, and Velocity
void MyHandleNoteOff(byte channel, byte pitch, byte velocity) {
digitalWrite(LED,LOW); //Turn LED off
}
Here is the starting MIDI codes that works on its own:
#include <MIDI.h> // Add Midi Library
#define LED 13 // Arduino Board LED is on Pin 13
//Create an instance of the library with default name, serial port and settings
MIDI_CREATE_DEFAULT_INSTANCE();
void setup() {
pinMode (LED, OUTPUT); // Set Arduino board pin 13 to output
MIDI.begin(2); // Initialize the Midi Library.
// OMNI sets it to listen to all channels.. MIDI.begin(2) would set it
// to respond to notes on channel 2 only.
MIDI.setHandleNoteOn(MyHandleNoteOn); // This is important!! This command
// tells the Midi Library which function you want to call when a NOTE ON command
// is received. In this case it's "MyHandleNoteOn".
MIDI.setHandleNoteOff(MyHandleNoteOff); // This command tells the Midi Library
// to call "MyHandleNoteOff" when a NOTE OFF command is received.
}
void loop() { // Main loop
MIDI.read(); // Continuously check if Midi data has been received.
}
// MyHandleNoteON is the function that will be called by the Midi Library
// when a MIDI NOTE ON message is received.
// It will be passed bytes for Channel, Pitch, and Velocity
void MyHandleNoteOn(byte channel, byte pitch, byte velocity) {
digitalWrite(LED,HIGH); //Turn LED on
}
// MyHandleNoteOFF is the function that will be called by the Midi Library
// when a MIDI NOTE OFF message is received.
// * A NOTE ON message with Velocity = 0 will be treated as a NOTE OFF message *
// It will be passed bytes for Channel, Pitch, and Velocity
void MyHandleNoteOff(byte channel, byte pitch, byte velocity) {
digitalWrite(LED,LOW); //Turn LED off
}
And here is the button code that works:
/*
Button
Turns on and off a light emitting diode(LED) connected to digital
pin 13, when pressing a pushbutton attached to pin 2.
The circuit:
* LED attached from pin 13 to ground
* pushbutton attached to pin 2 from +5V
* 10K resistor attached to pin 2 from ground
* Note: on most Arduinos there is already an LED on the board
attached to pin 13.
created 2005
by DojoDave <http://www.0j0.org>
modified 30 Aug 2011
by Tom Igoe
This example code is in the public domain.
http://www.arduino.cc/en/Tutorial/Button
*/
// constants won't change. They're used here to
// set pin numbers:
const int buttonPin = 2; // the number of the pushbutton pin
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState = 0; // variable for reading the pushbutton status
void setup() {
// initialize the LED pin as an output:
pinMode(ledPin, OUTPUT);
// initialize the pushbutton pin as an input:
pinMode(buttonPin, INPUT);
}
void loop() {
// read the state of the pushbutton value:
buttonState = digitalRead(buttonPin);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState == HIGH) {
// turn LED on:
digitalWrite(ledPin, HIGH);
} else {
// turn LED off:
digitalWrite(ledPin, LOW);
}
}