Hi All,
So i have managed to program an LED to be dimmed to off when the letter 'a' is held on the keyboard, and brightens when i hold 'q', but stays in the middle when no key is pressed, it works as i wanted.
However when i press and hold the key, it intitally detects the key press, then switches off, and then recognises it as held, it makes the led blink before doing what its told.
Is there a way of solving this to streamline the effect? Maybe ignoring that first bit of the output for a timed pause, or reducing that pause?
Thanks in advance.
My code is below. And also a small video of the system and shows the input from the keys and how they react. Im using Tera Term to activate it, and you can see the initial press of q, then the delay and then it recognises it etc.
** Edit it wont allow me to upload my video **
char incomingByte;
void setup() {
// put your setup code here, to run once:
pinMode(9, OUTPUT);
Serial.begin(9600);
analogWrite(9, 125);
}
void loop() {
// put your main code here, to run repeatedly:
Serial.print(incomingByte);
if (Serial.available() > 0 ) {
incomingByte = Serial.read();
if (incomingByte == 'q' )
{
analogWrite(9, 255);
delay(35);
}
if (incomingByte == 'a' )
{
analogWrite(9, 0);
delay(35);
}
}
else
{
incomingByte = ' ';
analogWrite(9, 125);
}
}