Quick suggestion on approaching this problem

Please explain what you mean by "pressing the key too fast" and "doesn't press the note". If you have added code to play tones, post the code as you now have it.

  if (chqC<thres)
  {
    store=HIGH;
  }    

  else if (chqC>=thres)

If chgC is not less than thres, is there any possible way for it not to be greater than or equal to thres?

dc42:
Please explain what you mean by "pressing the key too fast" and "doesn't press the note". If you have added code to play tones, post the code as you now have it.

I know the code is working when I test it in the serial monitor. However when I go to test it with the virtual keyboard most times a note is not being played. When it does play the note it is very quick and easily missed.

PaulS:

  if (chqC<thres)

{
    store=HIGH;
  }

else if (chqC>=thres)



If chgC is not less than thres, is there any possible way for it not to be greater than or equal to thres?

You are correct, any time chqC is not less than thres, it is automatically assumed that it will be greater than or equal to the thres. I have that line so that the store value can get overwritten.

I have that line so that the store value can get overwritten.

You need the else statement so that the store value can get overwritten, not the else if statement.

PaulS:
You need the else statement so that the store value can get overwritten, not the else if statement.

 else  {
       store=LOW;
         }

Something like that? Just tried running the code again and I'm having any luck.

Just tried running the code again and I'm having any luck.

Luck has nothing do with writing code that works. Debugging does. I don't see any Serial.print() statements in your code that tell you what is happening.

I left them out because I was scared that they would interfere with the AAC keys readings.
I wrote a separate code to test the laser and make sure it is working and I was using the right values.

FullyJosh:

dc42:
Please explain what you mean by "pressing the key too fast" and "doesn't press the note". If you have added code to play tones, post the code as you now have it.

I know the code is working when I test it in the serial monitor. However when I go to test it with the virtual keyboard most times a note is not being played. When it does play the note it is very quick and easily missed.

What exactly is the "virtual keyboard", and how have you connected it?

dc42:

FullyJosh:

dc42:
Please explain what you mean by "pressing the key too fast" and "doesn't press the note". If you have added code to play tones, post the code as you now have it.

I know the code is working when I test it in the serial monitor. However when I go to test it with the virtual keyboard most times a note is not being played. When it does play the note it is very quick and easily missed.

What exactly is the "virtual keyboard", and how have you connected it?

- YouTube I recorded a quick video to demonstrate the behaviour. Note that I decided to use an L.E.D. now because I thought it may have been some power issues with the actual laser but it appears it doesn't make a difference they are both behaving in the same way.

I am using a program called Mixcraft. I turned on the virtual keyboad in the program which allows me to use my computer keyboard. I don't think it's the virtual keyboard software's problem. I know this only because I also tried opening a word document and noticed that most times "a" doesn't appear, or it appears very delayed and some are dead on.

Anyone else have an idea on why the code would work in the serial monitor but not with aac keys enabled?

What data does Mixcraft expect? How is it supposed to know how long a note is?

dc42:
What data does Mixcraft expect? How is it supposed to know how long a note is?

Mixcraft will turn my computer keyboard into an actual musical keyboard. When I press the "a" key it plays the note and it will hold the note until I release my finger.

That's the problem then. There is no way that a serial port sending ASCII codes can convey information about how long a key was pressed. I think a Leonardo could do it, because I believe it can emulate a USB PC keyboard, for which the up- and down-codes are sent separately.

dc42:
That's the problem then. There is no way that a serial port sending ASCII codes can convey information about how long a key was pressed. I think a Leonardo could do it, because I believe it can emulate a USB PC keyboard, for which the up- and down-codes are sent separately.

Problem with that is that the Leonardo doesn't have enough analog pins.

Do you know how I can fix the issue where your code works flawlessly in the serial monitor but starts glitching when I turn on aac keys?

FullyJosh:

dc42:
That's the problem then. There is no way that a serial port sending ASCII codes can convey information about how long a key was pressed. I think a Leonardo could do it, because I believe it can emulate a USB PC keyboard, for which the up- and down-codes are sent separately.

Problem with that is that the Leonardo doesn't have enough analog pins.

Do you know how I can fix the issue where your code works flawlessly in the serial monitor but starts glitching when I turn on aac keys?

Not without using a Leonardo or other device that can emulate a keyboard that returns scan codes. How many analog inputs do you need, and why? The Leonardo has 12, and you can add more using an external ADC or analog multiplexer.

dc42:

FullyJosh:

dc42:
That's the problem then. There is no way that a serial port sending ASCII codes can convey information about how long a key was pressed. I think a Leonardo could do it, because I believe it can emulate a USB PC keyboard, for which the up- and down-codes are sent separately.

Problem with that is that the Leonardo doesn't have enough analog pins.

Do you know how I can fix the issue where your code works flawlessly in the serial monitor but starts glitching when I turn on aac keys?

Not without using a Leonardo or other device that can emulate a keyboard that returns scan codes. How many analog inputs do you need, and why? The Leonardo has 12, and you can add more using an external ADC or analog multiplexer.

dc42:

FullyJosh:

dc42:
That's the problem then. There is no way that a serial port sending ASCII codes can convey information about how long a key was pressed. I think a Leonardo could do it, because I believe it can emulate a USB PC keyboard, for which the up- and down-codes are sent separately.

Problem with that is that the Leonardo doesn't have enough analog pins.

Do you know how I can fix the issue where your code works flawlessly in the serial monitor but starts glitching when I turn on aac keys?

Not without using a Leonardo or other device that can emulate a keyboard that returns scan codes. How many analog inputs do you need, and why? The Leonardo has 12, and you can add more using an external ADC or analog multiplexer.

I'm just wondering because it has that same issue when using it to print the letter a in a word document.

I need 13 analog pins. I want to go one full octave from c to c

Why are you using analog pins, when it looks to me that you only need to detect whether a note is pressed or not?

dc42:
Why are you using analog pins, when it looks to me that you only need to detect whether a note is pressed or not?

I initially tried using the digital route and was noticing it was rather unstable.

But you are correct all I need to detect is on or off

Given that your threshold was 830 out of 1024 and you register a key press if the value is above threshold, I deduce that you are using pulldown pullup resistors, and that to use digital inputs, you need to decrease increase their value by a factor of about 4. If the Arduino by itself doesn't give good results using digital inputs, you could pass the signals through 74HC14 hex inverters first.

btw I've never used a Leonardo, but I understand that it can emulate a PC keyboard via the USB port.

[EDIT: corrected the above, on the assumption that interrupting a light beam causes a note to sound.]