Guys,
Need help.
I have an Arduino. Pins 2 & 3 are set to off (low), connected to pins 2 & 3 are two lines that send a On (high) signal. So on High, I want it to send keystrokes.
Something is off in my code and when I connect the Arduino to USB it just keeps sending keystrokes.
Requirements: pin 2 & pin 3 have to be on low/off position. The two wires are sending the high (on) voltage signal.
The code is below.
Thank you,
Super Duper Noob
#define buttonPin1 2
#define buttonPin2 3
int state = 0;
void setup()
{
Serial.begin(9600);
pinMode(buttonPin1, INPUT);
pinMode(buttonPin2, INPUT);
digitalWrite(buttonPin1, 0);
digitalWrite(buttonPin2, 0);
delay(200);
}
void loop()
{
// ButtonPin1
state = digitalRead(buttonPin1);
if (state != 1) {
buf[0] = 0;
buf[2] = 27;
Serial.write(buf, 8);
releaseKey();
delay(900);
}
// ButtonPin2
state = digitalRead(buttonPin2);
if (state != 1) {
buf[0] = 0;
buf[2] = 23;
Serial.write(buf, 8);
releaseKey();
delay(200);
}
}
void releaseKey()
{
buf[0] = 0;
buf[2] = 0;
Serial.write(buf, 8); // Release key
delay(500);
}