Hi jimmy. I finally got home to my PC and upload the sketch with the array query. From what you said this makes sense that the array is only used within the context of that IF condition. I learn something new every day. So this sketch is basically a project to try getting my son into programming *(and me as it turns out). This is the old chestnut of the midi drum. I thought great - a simple one since he loves drums! What We're looking to do is to interface to a midi controller (which all works) and then choose different drum kits by selecting with simple input switches. As you can see the sketch is so basic but I tried so long trying to figure out menu systems that my son was losing interest. So we simplified it to just 2 buttons to select two kits, but even this I can get working. Any advice or pointers on how to set maybe a global array and then change it's values as per a simple switch press.
Here goes... much cut down from the original 4 button. Again I realize how basic this is but just to try prove a principle before going too in deep. I have NO previous programming experience and it shows. But we start somewhere.
// constants won't change. They're used here to
// set pin numbers:
const int button1 = 22; // the number of the pushbutton
const int button2 = 23; // the number of the pushbutton
const int ledPin = 13; // the number of the LED pin
// variables will change:
int buttonState1 = 0; // variable for reading the pushbutton status
int buttonState2 = 0; // variable for reading the pushbutton status
//Define initial variables for first use
// Order listed below
int KitSet[7] = {
90,30,3,4,5,6,7};
//Define now the MIDI PARTS -
#define drumchan 16
//Define input pins
#define piezoAPin 0 // single piezo on Analogue pin 0
#define ledPin 13 // for midi out status and button press status indication
#define PIEZOTHRESHOLD 100 // analog threshold for piezo sensing
int val,t; // for use as velicity sense from Piezo - not used at present
// include the library code:
#include <LiquidCrystal.h>
// initialize the library with the numbers of the interface pins
LiquidCrystal lcd(12, 11, 5, 4, 3, 2); // 20x4 LCD connected
void setup() {
pinMode(ledPin, OUTPUT); // SETS LED BLINK ON INPUT / OUTPUT
pinMode(button1, INPUT); // Set the pushbutton pins as an input:
pinMode(button2, INPUT);
Serial.begin(31250); // set MIDI baud rate
lcd.begin(20, 4);
// Print a message to the LCD.
lcd.clear();
lcd.setCursor(1,1);
lcd.print("Button 1 for Kit 1");
lcd.setCursor(1,2);
lcd.print("Button 2 for Kit 2");
}
// Start looping the inputs
void loop(){
// read the state of the pushbutton value:
buttonState1 = digitalRead(button1);
buttonState2 = digitalRead(button2);
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState1 == HIGH) {
int KitSet[7] = {
36,6,7,8,9,10,11 }; // New set of numbers in the array for button 1 press
digitalWrite(ledPin, HIGH); // turn LED on: Visual indication that button press was registered
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Kit Set 1 selected");
}
// check if the pushbutton is pressed.
// if it is, the buttonState is HIGH:
if (buttonState2 == HIGH) {
int KitSet[7] = {
48,12,13,14,15,16,17 }; // New set of numbers in the array for button 1 press
digitalWrite(ledPin, HIGH); // turn LED on: Visual indication that button press was registered
lcd.clear();
lcd.setCursor(1,0);
lcd.print("Kit Set 2 selected");
}
// Enter the MIDI setup here
//
// deal with first piezo, this is kind of a hack
val = analogRead(piezoAPin);
if( val >= PIEZOTHRESHOLD ) {
t=0;
while(analogRead(piezoAPin) >= PIEZOTHRESHOLD/2) {
t++;
}
noteOn(drumchan,KitSet[0], t*2); // Where KitSet[0] is the first value of the array and used in this example
// Note that the other parameters in the array would be for different
// later defined piezo inputs
;
delay(50);
noteOff(drumchan,KitSet[0],0);
}
}
// Send a MIDI note-on message.
void noteOn(byte channel, byte note, byte velocity) {
midiMsg( (0x90 | channel), note, velocity);
}
// Send a MIDI note-off message. BUT actually sending a NOTE ON (as this simluates a note off when velocity = 0
void noteOff(byte channel, byte note, byte velocity) {
midiMsg( (0x90 | channel), note, 0x00);
}
// Send a general MIDI message
void midiMsg(byte cmd, byte data1, byte data2) {
digitalWrite(ledPin,HIGH); // indicate we're sending MIDI data
Serial.write(cmd);
Serial.write(data1);
Serial.write(127); // Just set max velocity otherwise use byte data2
digitalWrite(ledPin,LOW);
Serial.print (data1);
}