I am rather new to Arduino. I am currently trying to write a simple program as a test for a later project. I have a load cell plugged in to my Arduino Due, and am currently using the load cell as a button. I would like to use the Keyboard.press command print a letter when the load cell button is pressed.
I started with the sample code I found on Arduino’s website for using the Keyboard.press command, and also included a Serial.println command to test that the program is indeed detecting a button press.
No matter which of the Keyboard commands I use, it seems as if nothing is happening with the keyboard operation. I can see in the serial monitor that it is working, and I have an open, active Notepad window open to receive the keystrokes.
Can someone help me figure out how to make the keyboard commands work?
void setup() {
Serial.begin(9600);
Keyboard.begin();
}
void loop() {
//set up to read from load cell
// read the input on analog pin 0:
int sensorValue = analogRead(A0);
// Convert the analog reading (which goes from 0 - 1023) to a voltage (0 - 5V):
float voltage = sensorValue * (5.0 / 1023.0);
// print out the value you read:
//Serial.println(voltage);
//THIS PART DOESNT WORK. IT PRINTS "pinch!" but not the keyboard.press
if (voltage >1){
delay(200);
Keyboard.press('p');
delay(50);
Keyboard.write('w');
delay(50);
Keyboard.write(65);
delay(50);
Keyboard.println("Hello!");
delay(50);
Serial.println("pinch!");
delay(200);
Keyboard.releaseAll();
delay(200);
}
}
Thank You!