I am on a long journey to make a myoelectric virtual wireless keyboard. I know very little about electronics and nothing about code. However, there are generous people such as those at Hacklabs in Toronto that are helping along the way.
Currently I have a code for 5 input buttons to make a Teensy++2 a USB keyboard courtesy of Hacklabs. We ran out of time as I am a slow learner so there was not an opportunity to tidy up the code. I will attempt to write code to allow the entry of numbers and symbols after I get to the next step. At the moment I can use various combinations of the 5 buttons to type into my laptop.
#define maskC B00011111
#define unpress_time 200
int keymap[32] = {-1,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23,24,25,26,27,28,29,40,42,44,57,0};
//enter=40,backspace=42, tab=43, space=44, caps lock 57
void setup() {
Serial.begin(115200);
DDRC ^= maskC;
PORTC ^= maskC;
}
void loop() {
static byte keysdown = 0;
static byte prevFull = 0;
static byte prevFull_release = 0;
static unsigned long tlpress = 0;
static unsigned long tlunpress = 0;
byte full = ~(PINC) & maskC;
if(full && !keysdown) {
keysdown = 1;
tlpress = micros();
tlunpress = 0;
}
else if(!full && keysdown) {
keysdown = 0;
Keyboard.set_key1(keymap[prevFull_release]);
Keyboard.send_now();
Keyboard.set_key1(0);
Keyboard.send_now();
tlunpress = 0;
prevFull = 0;
prevFull_release = 0;
}
if(keysdown) {
if(full < prevFull) {
tlunpress = millis();
if((millis() - tlunpress) > unpress_time) {
prevFull_release = prevFull;
}
prevFull = full;
}
else if(full > prevFull) {
prevFull = full;
prevFull_release = prevFull;
tlunpress = 0;
tlpress = millis();
}
else {
//full == prevFull
if(tlunpress != 0 && (millis() - tlunpress) > unpress_time) {
prevFull_release = prevFull;
tlunpress = 0;
}
}
}
delay(5);
}
The next is to make this a wireless keyboard to isolate the myoelectric and keyboard circuits from any display device.
I went to Creatroninc in Toronto and picked up a bluetooth module
and a logic converter
I soldered the headers to the converter and wired up the bluetooth to the converter and Teensy.
My question at this point is what do I have to do to this code to get the same results with the bluetooth as I do as a Usb keyboard?
Any assistance is most appreciated. As you can tell from my questions that I am learning on the fly so please be patient.
Thank you very much.
Paul Hirst