hi everyone,
what i have is; an arduino uno, a 4 wire resistive touch screen (taken from a nintendo ds xl), a blinkM smart LED, and a momentary switch, and a korg kaoss pad kp3. what i want to do is program my arduino to read the touch screen and the momentary switch then convert the messages and values from them, turn the readings into midi data, then send that midi data for control change one the kaoss pad.
The way i want it to work is for the touch screen (from the nintendo ds) to act as a remote controller for the touch screen already existing in the kp3. i also want the momentary switch to do the same funtion as the HOLD button that is already on the kp3. while all of this is happening, i want the blinkM LED to chnge colours at its own pace while the ds touch screen is not in use, but when the ds touch srenn is in use, have the led change colours as the values on the ds touch screen change.
This is the sketch i have written so far:
/*****************************************
// Jayke's Midi Pad Code
//
//Reads a 4 wire touch screen and a momentary switch
//
//Sends serial data on channel 1 to a korg KP3
//
//Sends serial data to a blinkM Smart LED
//
//Connect one pin of the switch to GND, the other to D9 on the
Arduino
//Connect the +X axis pin of the touch screen to AD0 on the arduino (a second
wire goes to a 10k ohm resistor then to GND)
//Connect the -X axis pin of the touch screen to AD1 on the arduino (a second
wire goes to a 10k ohm resistor then to GND)
//Connect the +Y axis pin of the touch screen to AD2 on the arduino (a second
wire goes to a 10k ohm resistor then to GND)
//Connect the -Y axis pin of the touch screen to AD3 on the arduino (a second
wire goes to a 10k ohm resistor then to GND)
//Connect one pin of blinkM smart LED to D3 on the arduino
//Connect one pin of blinkM smart LED to D5 on the arduino
//Connect one pin of blinkM smart LED to D6 on the arduino
//Connect one pin of blinkM smart LED to 5v
//
//Midi socket is connected as: (looking from behind at the pins)
//
// __---__
// / 2 \ Pin 2 -> GND
// ( 4 5 ) Pin 4 -> 220ohm resistor -> 5v
// \ 1 3 / Pin 5 -> 220ohm resistor -> Arduino TX Pin
// """"" Pins 1 / 3 open
*****************************************/
#define analogPin0 0 // touchXhigh
#define analogPin1 1 // touchXlow
#define analogPin2 2 // touchYhigh
#define analogPin3 3 // touchYlow
#define digitalPin9 9 // momentary switch
#define Debounce 30
int touchXhighValue = 0;
int touchXlowValue = 0;
int touchYhighValue = 0;
int touchYlowValue = 0;
int switchValue = 0;
int switchState = 0;
int touchXhighValueLast = 0;
int touchXlowValueLast = 0;
int touchYhighValueLast = 0;
int touchYlowValueLast = 0;
byte i,valt;
void setup() {
Serial.begin(31250); // set MIDI baud rate
Serial.flush();
for (i = 2; i <=11;i++){ //turn on internal pullups for switches
digitalWrite(i, HIGH);
}
}
void loop() {
//Read momentary Switch
switchValue = digitalRead(digitalPin9);
if(switchValue ==LOW && switchState ==0){ //first press
switchState =1;
midiCC(0xB0, 0, 127); // sends effect hold for korg kaoss pad
delay(Debounce);
}
if(switchValue ==HIGH && switchState ==1){
switchState =2;
}
if(switchValue ==LOW && switchState ==2){ // second press
switchState =3;
midiCC(0xB0, 0, 0); // sends effect hold for korg kaoss pad
delay(Debounce);
}
if(switchValue ==HIGH && switchState ==3){
switchState =0;
}
//Read touchXhigh
touchXhighValue = analogRead(analogPin0);
if(touchXhighValue != touchXhighValueLast){
touchXhighValue = map(touchXhighValue,0,1016,0,127); //maps the value range of touchXhigh to midi 0->127
midiCC(0xB0, 12, touchXhighValue); // sends midi control change for korg kp3 touch pad
touchXhighValueLast = touchXhighValue;
}
//Read touchXlow
touchXlowValue = analogRead(analogPin1);
if(touchXlowValue != touchXlowValueLast){
touchXlowValue = map(touchXlowValue,0,1016,0,127); //maps the value range of touchXlow to midi 0->127
midiCC(0xB0, 12, touchXlowValue); // sends midi control change for korg kp3 touch pad
touchXlowValueLast = touchXlowValue;
}
//Read touchYhigh
touchYhighValue = analogRead(analogPin2);
if(touchYhighValue != touchYhighValueLast){
touchYhighValue = map(touchYhighValue,0,1016,0,127); //maps the value range of touchYhigh to midi 0->127
midiCC(0xB0, 13, touchYhighValue); // sends midi control change for korg kp3 touch pad
touchYhighValueLast = touchYhighValue;
}
//Read touchYlow
touchYlowValue = analogRead(analogPin3);
if(touchYlowValue != touchYlowValueLast){
touchYlowValue = map(touchYlowValue,0,1016,0,127); //maps the value range of touchYlow to midi 0->127
midiCC(0xB0, 13, touchYlowValue); // sends midi control change for korg kp3 touch pad
touchYlowValueLast = touchYlowValue;
}
}
void midiCC(char command, char value1, char value2){
Serial.print(command, BYTE);
Serial.print(value1, BYTE);
Serial.print(value2, BYTE);
}
what this should do (fingers crossed) is:
- read the momentary switch
- send serial for control change on the korg kaoss pad for the hold button
- read the ds touchscreen
- send serial for control change on the korg kp3 for the touch pad
i havent done anything for the blinkM smart LED yet, as i have no idea where to start with it
can anyone please look over the code and tell me if A: im going in the right direction, or B: give me some pointers with my code, C: help me with programming the BlinkM LED?
any help, comments, suggestion at all would be greatly appreciated
thanks