Sending Keyboard.h to Serial1
Posted: Sun Dec 26, 2021 11:48 pm
Hello All, yes it's me again.
I am working on a small project that requires some Keyboard.press functions. The only thing is, I need them to be sent via Serial1 instead of the default. Strange, but this is the only way I have found that my over all project will work (issue with serial read/write not working until serial monitor has been opened and instantly closed).
Anyway, I have successfully managed to get Keyboard.press to work with the on board USB port, but I need to be able to send it to Serial1 instead. Here is a the basic code that I am working with (extract from the overall sketch);
Yes I know that the button press could be coded alot better, but I wanted to keep things really simple for now.
The above works fine when using the default USB port on the board (STM32F401CCU6)
So, is it possible to get this code working with Serial1? If so, would someone be kind enough to talk me through it?
Thanks in advance
Tim
I am working on a small project that requires some Keyboard.press functions. The only thing is, I need them to be sent via Serial1 instead of the default. Strange, but this is the only way I have found that my over all project will work (issue with serial read/write not working until serial monitor has been opened and instantly closed).
Anyway, I have successfully managed to get Keyboard.press to work with the on board USB port, but I need to be able to send it to Serial1 instead. Here is a the basic code that I am working with (extract from the overall sketch);
Code: Select all
#include <Keyboard.h>
#define Button PB2
void setup() {
pinMode(Button, INPUT_PULLUP);
Serial1.begin(115200);
Keyboard.begin();
}
void loop() {
if (digitalRead(Button) == HIGH)
{ Keyboard.press('a'); Keyboard.releaseAll(); delay(150); }
}
The above works fine when using the default USB port on the board (STM32F401CCU6)
So, is it possible to get this code working with Serial1? If so, would someone be kind enough to talk me through it?
Thanks in advance
Tim