chorded keyboard with buttons on glove fingertips so you can type on the go - maps 5 digit binary input to various letters/symbols; extra button to switch caps lock on/off

Dependencies:   PinDetect USBDevice mbed

Embed: (wiki syntax)

« Back to documentation index

Show/hide line numbers G_type.cpp Source File

G_type.cpp

00001 #include "mbed.h"
00002 #include "PinDetect.h"
00003 
00004 PinDetect pb0(D2, PullUp);
00005 PinDetect pb1(D6, PullUp);
00006 PinDetect pb2(D7, PullUp);
00007 PinDetect pb3(D5, PullUp);
00008 PinDetect pb4(D4, PullUp);
00009 PinDetect pb5(D3, PullUp);
00010 DigitalOut myled(LED1);
00011 
00012 Serial pc(USBTX, USBRX);
00013 
00014 int pinbus[5] = {0, 0, 0, 0, 0};
00015 int toggle = 0;
00016 
00017 char map[2][31] = {
00018 {'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z', '.', '?', ' ', '\n', '\b'},
00019 {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R', 'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '.', '?', ' ', '\n', '\b'},
00020 };
00021 
00022 int pinbusvalues[31][5] = {
00023 {0, 0, 0, 0, 1}, {0, 0, 0, 1, 1}, {0, 0, 1, 0, 1}, {0, 1, 0, 0, 1}, {1, 0, 0, 0, 1},
00024 {0, 0, 0, 1, 0}, {0, 0, 1, 1, 0}, {0, 1, 0, 1, 0}, {1, 0, 0, 1, 0}, {0, 0, 1, 0, 0}, 
00025 {0, 1, 1, 0, 0}, {1, 0, 1, 0, 0}, {0, 1, 0, 0, 0}, {1, 1, 0, 0, 0}, {1, 0, 0, 0, 0},
00026 {0, 0, 1, 1, 1}, {0, 1, 0, 1, 1}, {1, 0, 0, 1, 1}, {0, 1, 1, 1, 0}, {1, 0, 1, 1, 0},
00027 {1, 1, 0, 1, 0}, {1, 1, 0, 0, 1}, {0, 1, 1, 0, 1}, {1, 0, 1, 0, 1}, {1, 1, 0, 1, 1},
00028 {1, 0, 1, 1, 1}, {1, 1, 1, 0, 0}, {1, 1, 1, 0, 1}, {1, 1, 1, 1, 1}, {0, 1, 1, 1, 1}, 
00029 {1, 1, 1, 1, 0}
00030 };
00031 
00032 void CAPSpressed(void){
00033     toggle = !toggle;
00034 }
00035 void f1pressed(void){
00036     pinbus[0] = 1;
00037 }
00038 void f2pressed(void){
00039     pinbus[1] = 1;
00040 }
00041 void f3pressed(void){
00042     pinbus[2] = 1;
00043 }
00044 void f4pressed(void){
00045     pinbus[3] = 1;
00046 }
00047 void f5pressed(void){
00048     pinbus[4] = 1;
00049 }
00050 
00051 void keyPressed(void){
00052     for (int i=0; i<31; i++){
00053         if (pinbus[0] == pinbusvalues[i][0]&&pinbus[1] == pinbusvalues[i][1]&&pinbus[2] == pinbusvalues[i][2]&&pinbus[3] == pinbusvalues[i][3]&&pinbus[4] == pinbusvalues[i][4]) {
00054             pc.printf("%c", map[toggle][i]);
00055         }
00056     }
00057     for (int k=0; k<5; k++) {
00058         pinbus[k] = 0;
00059     }
00060 }
00061 
00062 int main() {
00063     pc.baud(9600);
00064     pb0.attach_deasserted(&CAPSpressed);
00065     pb1.attach_deasserted(&f1pressed);
00066     pb2.attach_deasserted(&f2pressed);
00067     pb3.attach_deasserted(&f3pressed);
00068     pb4.attach_deasserted(&f4pressed);
00069     pb5.attach_deasserted(&f5pressed);
00070     pb1.attach_asserted(&keyPressed);
00071     pb2.attach_asserted(&keyPressed);
00072     pb3.attach_asserted(&keyPressed);
00073     pb4.attach_asserted(&keyPressed);
00074     pb5.attach_asserted(&keyPressed);
00075     //set frequency
00076     pb0.setSampleFrequency();
00077     pb1.setSampleFrequency();
00078     pb2.setSampleFrequency();
00079     pb3.setSampleFrequency();
00080     pb4.setSampleFrequency();
00081     pb5.setSampleFrequency();
00082     
00083     while(1){
00084         myled = !myled;
00085         wait(0.2);
00086     }            
00087 }