hi
I thank capicoso for his wisdom and reply and the approach to the code did indeed work.
I have again been banging my head against a wall for a week now
to try and improve this approach.
with the code which has been implemented using capicoso approach
if i play a note say C (all great plays a C)
then while C is still pressed play note D (all is great plays a D)
if i then release D while C is still pressed I would like it to go back to playing a C
at the moment it still plays a D
its like i want to achieve a current status on the current note
I hoping someone might be able to unlock me going round and round in circles
thanking you in advance
#include <MIDI.h>
#define LATCH 7 //Variable for DAC
#define CLOCK 6 //Variable for DAC
#define DATA 4 //Variable for DAC
#define HALF_CLOCK_PERIOD 1 //Variable for DAC
uint16_t DACoutput=530; //Variable for DAC
int led = 8; // Opens Gate
//test variable
byte noteOnCounter=0;
byte noteOffCounter = 0;
void setup(){
Serial.begin(31250);
MIDI.setHandleNoteOn(HandleNoteOn);
MIDI.begin(1);//Launch MIDI and listen to channel 1
pinMode(led,OUTPUT); //Opens Gate
//DAC setup pins
pinMode(DATA, OUTPUT);pinMode(CLOCK,OUTPUT);pinMode(LATCH,OUTPUT);digitalWrite(DATA,LOW);digitalWrite(CLOCK,LOW);digitalWrite(LATCH,LOW);
}// end of setup
void loop()
{
MIDI.read();
}// End of void loop
void HandleNoteOn(byte channel,byte note,byte velocity){
digitalWrite(led,HIGH);
if (velocity > 0){//if its a real note
if ( note > 10){if (note < 128){DACoutput = note * 300; writeValue(DACoutput);
noteOnCounter++;
if (noteOnCounter == 4){noteOnCounter = 0;}
}}//End of if ( note > 10){if (note < 128)
}//end of if velocity > 0
if (velocity == 0) {noteOffCounter++;if (noteOffCounter == 4){noteOffCounter = 0;}
if (noteOnCounter == noteOffCounter){ digitalWrite(led,LOW);} }
} //end of HandleNoteOn
// ad420 Bit DAC Code compressed
void writeValue(uint16_t value){ //start of sequence
digitalWrite(LATCH,LOW);digitalWrite(CLOCK,LOW);for(int i=15;i>=0;i--){digitalWrite(DATA,((value&(1<<i)))>>i);
delayMicroseconds(HALF_CLOCK_PERIOD);digitalWrite(CLOCK,HIGH);delayMicroseconds(HALF_CLOCK_PERIOD);digitalWrite(CLOCK,LOW);}
digitalWrite(DATA,LOW);digitalWrite(CLOCK,LOW);digitalWrite(LATCH,HIGH);delayMicroseconds(HALF_CLOCK_PERIOD);digitalWrite(LATCH,LOW);}