Setup:
One Laser beam to a LDR. When the beam is broken, it turns on a LED and sends a midi note (middle C, 0x 60) through a midi output (http://itp.nyu.edu/physcomp/Labs/MIDIOutput). However, the LED is lit up for as long as I am breaking the beam, but the note is strumming with the same pace as the delay eventhought the value from the LDR is >=600. It seems like the midimessage keeps jumping into the else loop.
How can I make the midi note last for as long as I am breaking the beam?
If I make the delay longer the note will hold for that amount of time so that is not really working.
Anyone who can see the soulution for my problem? or have a nicer way of writing the code?
Here is the code I'm using--->
////////////////////////////////////////////////////////////////////////////////////////////////////////
// One string laserharp, sending a midi message when beam is broken
// Variables: /////////////////////////////////////////////////////////////////////////////////////////// #define MIDICMD_NOTEON 0x90 // MIDI command (Note On, Channel 0)
int sensorPin = 2; // select the input pin for the LDR
int ledPin = 13; // select the control pin for the LED
int val = 0; // variable to store the value coming from the sensor
Every time you go around in your loop you send a new note on if val >= 600 is that really what you want ?
I'm not exactly a MIDI specialist but i think you need to implement some kind of state maintenance to keep track of the state of the note on or off, so you only send new note on commands if the note is off otherwise i think you will continously retrigger the note if val >= 600
Hej MikMo, thanks for your quick reply.
ops, yes, i should declare the led Pin as output.
Every time you go around in your loop you send a new note on if val >= 600 is that really what you want ?
Once the val is >=600 I don't want to send a new command until the value is <600. Yeah. I believe your conclusion is correct. It's now just re triggering.
Anyone who could show me how to hold the note on-state until the value is less than 600? Or... know some other topic or code snippet i should check out. Has this something to do with a for loop, could i write a stop running until value is <600 in some way?
But then I would like to use the the code for several LDR inputs later. Maybe writing a wait would also affect the other inputs.
(Gosh, I tried to desolder some buttons from an old alarmclock. Really got an instataneous headach from the fumes. Also tried grabbing the soldering iron on the very hot are instead of the handle. Thinks it's time to call it a day maybe.)