Code for text entry device-Type using sign language

Dependencies:   PinDetect_KL25Z USBDevice mbed

Committer:
MayaMardini
Date:
Mon Sep 14 02:03:49 2015 +0000
Revision:
0:ce783f27babb
SignLanguage_TextEntry

Who changed what in which revision?

UserRevisionLine numberNew contents of line
MayaMardini 0:ce783f27babb 1 #include "mbed.h"
MayaMardini 0:ce783f27babb 2 #include "USBKeyboard.h"
MayaMardini 0:ce783f27babb 3 #include "PinDetect.h"
MayaMardini 0:ce783f27babb 4
MayaMardini 0:ce783f27babb 5 PinDetect key1(D1), key2(D2), key3(D3), key4(D4), key5(D5), key6(D6), key7(D7), key8(D8), key9(D9), key10(D10), key11(D11), key12(D12), key13(D13);
MayaMardini 0:ce783f27babb 6 //IMPORTANT Keys 1, 7, and 13 were not used in the code below to keep my total switches used to 10. However, those pins can be added so that the entire alphabet can be properly signed.
MayaMardini 0:ce783f27babb 7 //Without them there are a couple letters that are signed differently than the actual way.
MayaMardini 0:ce783f27babb 8
MayaMardini 0:ce783f27babb 9 int key1Stat;
MayaMardini 0:ce783f27babb 10 int key2Stat;
MayaMardini 0:ce783f27babb 11 int key3Stat;
MayaMardini 0:ce783f27babb 12 int key4Stat;
MayaMardini 0:ce783f27babb 13 int key5Stat;
MayaMardini 0:ce783f27babb 14 int key6Stat;
MayaMardini 0:ce783f27babb 15 int key7Stat;
MayaMardini 0:ce783f27babb 16 int key8Stat;
MayaMardini 0:ce783f27babb 17 int key9Stat;
MayaMardini 0:ce783f27babb 18 int key10Stat;
MayaMardini 0:ce783f27babb 19 int key11Stat;
MayaMardini 0:ce783f27babb 20 int key12Stat;
MayaMardini 0:ce783f27babb 21 int key13Stat;
MayaMardini 0:ce783f27babb 22 int totalKeys1;
MayaMardini 0:ce783f27babb 23 int totalKeys;
MayaMardini 0:ce783f27babb 24 int value;
MayaMardini 0:ce783f27babb 25 int i;
MayaMardini 0:ce783f27babb 26 char letter;
MayaMardini 0:ce783f27babb 27 int keyNumbers[]={39036, 4126, 32798, 2047, 34814, 32767, 2174, 63, 8191, 10365, 255, 2205, 4222, 6142, 16383, 511, 158, 127, 10396, 34972, 732, 221, 31, 2716, 34941, 68219, 4095, 542, 2078};
MayaMardini 0:ce783f27babb 28 char keyLetters [] ={'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', ' ', '\b', '\n'};
MayaMardini 0:ce783f27babb 29
MayaMardini 0:ce783f27babb 30 //keyNumbers is an array of unique values that correspond to a combinations of buttos pressed to form a letter that matches in its position in the array to a letter in keyLetters
MayaMardini 0:ce783f27babb 31
MayaMardini 0:ce783f27babb 32 USBKeyboard key;
MayaMardini 0:ce783f27babb 33
MayaMardini 0:ce783f27babb 34 void key1on(void){ // These functions give a particular value to a key when pressed
MayaMardini 0:ce783f27babb 35 key1Stat = 5;
MayaMardini 0:ce783f27babb 36 }
MayaMardini 0:ce783f27babb 37 void key2on(void){
MayaMardini 0:ce783f27babb 38 key2Stat = 31;
MayaMardini 0:ce783f27babb 39 }
MayaMardini 0:ce783f27babb 40 void key3on(void){
MayaMardini 0:ce783f27babb 41 key3Stat = 63;
MayaMardini 0:ce783f27babb 42 }
MayaMardini 0:ce783f27babb 43 void key4on(void){
MayaMardini 0:ce783f27babb 44 key4Stat= 127;
MayaMardini 0:ce783f27babb 45 }
MayaMardini 0:ce783f27babb 46 void key5on(void){
MayaMardini 0:ce783f27babb 47 key5Stat = 255;
MayaMardini 0:ce783f27babb 48 }
MayaMardini 0:ce783f27babb 49 void key6on(void){
MayaMardini 0:ce783f27babb 50 key6Stat = 511;
MayaMardini 0:ce783f27babb 51 }
MayaMardini 0:ce783f27babb 52 void key7on(void){
MayaMardini 0:ce783f27babb 53 key7Stat = 1023;
MayaMardini 0:ce783f27babb 54 }
MayaMardini 0:ce783f27babb 55 void key8on(void){
MayaMardini 0:ce783f27babb 56 key8Stat = 2047;
MayaMardini 0:ce783f27babb 57 }
MayaMardini 0:ce783f27babb 58 void key9on(void){
MayaMardini 0:ce783f27babb 59 key9Stat = 4095;
MayaMardini 0:ce783f27babb 60 }
MayaMardini 0:ce783f27babb 61 void key10on(void){
MayaMardini 0:ce783f27babb 62 key10Stat = 8191;
MayaMardini 0:ce783f27babb 63 }
MayaMardini 0:ce783f27babb 64 void key11on(void){
MayaMardini 0:ce783f27babb 65 key11Stat = 16383;
MayaMardini 0:ce783f27babb 66 }
MayaMardini 0:ce783f27babb 67 void key12on(void){
MayaMardini 0:ce783f27babb 68 key12Stat = 32767;
MayaMardini 0:ce783f27babb 69 }
MayaMardini 0:ce783f27babb 70 void key13on(void){
MayaMardini 0:ce783f27babb 71 key13Stat = 65535;
MayaMardini 0:ce783f27babb 72 }
MayaMardini 0:ce783f27babb 73
MayaMardini 0:ce783f27babb 74 int main() {
MayaMardini 0:ce783f27babb 75
MayaMardini 0:ce783f27babb 76 key1.mode(PullUp); //set the pins to pullup mode
MayaMardini 0:ce783f27babb 77 key2.mode(PullUp);
MayaMardini 0:ce783f27babb 78 key3.mode(PullUp);
MayaMardini 0:ce783f27babb 79 key4.mode(PullUp);
MayaMardini 0:ce783f27babb 80 key5.mode(PullUp);
MayaMardini 0:ce783f27babb 81 key6.mode(PullUp);
MayaMardini 0:ce783f27babb 82 key7.mode(PullUp);
MayaMardini 0:ce783f27babb 83 key8.mode(PullUp);
MayaMardini 0:ce783f27babb 84 key9.mode(PullUp);
MayaMardini 0:ce783f27babb 85 key10.mode(PullUp);
MayaMardini 0:ce783f27babb 86 key11.mode(PullUp);
MayaMardini 0:ce783f27babb 87 key12.mode(PullUp);
MayaMardini 0:ce783f27babb 88 key13.mode(PullUp);
MayaMardini 0:ce783f27babb 89
MayaMardini 0:ce783f27babb 90 key1.setSampleFrequency(); //Set the sampling frequency for each pin
MayaMardini 0:ce783f27babb 91 key2.setSampleFrequency();
MayaMardini 0:ce783f27babb 92 key3.setSampleFrequency();
MayaMardini 0:ce783f27babb 93 key4.setSampleFrequency();
MayaMardini 0:ce783f27babb 94 key5.setSampleFrequency();
MayaMardini 0:ce783f27babb 95 key6.setSampleFrequency();
MayaMardini 0:ce783f27babb 96 key7.setSampleFrequency();
MayaMardini 0:ce783f27babb 97 key8.setSampleFrequency();
MayaMardini 0:ce783f27babb 98 key9.setSampleFrequency();
MayaMardini 0:ce783f27babb 99 key10.setSampleFrequency();
MayaMardini 0:ce783f27babb 100 key11.setSampleFrequency();
MayaMardini 0:ce783f27babb 101 key12.setSampleFrequency();
MayaMardini 0:ce783f27babb 102 key13.setSampleFrequency();
MayaMardini 0:ce783f27babb 103
MayaMardini 0:ce783f27babb 104 key1.attach_asserted(&key1on); //in pull up mode this checks to see if a button is pressed
MayaMardini 0:ce783f27babb 105 key2.attach_asserted(&key2on);
MayaMardini 0:ce783f27babb 106 key3.attach_asserted(&key3on);
MayaMardini 0:ce783f27babb 107 key4.attach_asserted(&key4on);
MayaMardini 0:ce783f27babb 108 key5.attach_asserted(&key5on);
MayaMardini 0:ce783f27babb 109 key6.attach_asserted(&key6on);
MayaMardini 0:ce783f27babb 110 key7.attach_asserted(&key7on);
MayaMardini 0:ce783f27babb 111 key8.attach_asserted(&key8on);
MayaMardini 0:ce783f27babb 112 key9.attach_asserted(&key9on);
MayaMardini 0:ce783f27babb 113 key10.attach_asserted(&key10on);
MayaMardini 0:ce783f27babb 114 key11.attach_asserted(&key11on);
MayaMardini 0:ce783f27babb 115 key12.attach_asserted(&key12on);
MayaMardini 0:ce783f27babb 116 key13.attach_asserted(&key13on);
MayaMardini 0:ce783f27babb 117
MayaMardini 0:ce783f27babb 118 while(1) {
MayaMardini 0:ce783f27babb 119 i=0;
MayaMardini 0:ce783f27babb 120 value=0;
MayaMardini 0:ce783f27babb 121 totalKeys1= key1Stat + key2Stat + key3Stat + key4Stat + key5Stat + key6Stat + key7Stat + key8Stat + key9Stat + key10Stat + key11Stat + key12Stat + key13Stat; //Sum the values of the buttons that are pressed
MayaMardini 0:ce783f27babb 122 wait(0.3);
MayaMardini 0:ce783f27babb 123 totalKeys= key1Stat + key2Stat + key3Stat + key4Stat + key5Stat + key6Stat + key7Stat + key8Stat + key9Stat + key10Stat + key11Stat + key12Stat + key13Stat; // Sum again after some time for debouncing
MayaMardini 0:ce783f27babb 124
MayaMardini 0:ce783f27babb 125 if (totalKeys > 0 && totalKeys1==totalKeys) {
MayaMardini 0:ce783f27babb 126 while (totalKeys != value && i < sizeof(keyNumbers)){
MayaMardini 0:ce783f27babb 127 value = keyNumbers[i+1]; //see if the sum matches one of the values in the array of numbers that correspond to a letter
MayaMardini 0:ce783f27babb 128 i++;
MayaMardini 0:ce783f27babb 129
MayaMardini 0:ce783f27babb 130 }
MayaMardini 0:ce783f27babb 131
MayaMardini 0:ce783f27babb 132 key.printf("%c",keyLetters[i]); //print the letter that corresponds to the value in the keyNumbers Array
MayaMardini 0:ce783f27babb 133 key1Stat=0; //make sure to set all the states of the keys back to zero
MayaMardini 0:ce783f27babb 134 key2Stat=0;
MayaMardini 0:ce783f27babb 135 key3Stat=0;
MayaMardini 0:ce783f27babb 136 key4Stat=0;
MayaMardini 0:ce783f27babb 137 key5Stat=0;
MayaMardini 0:ce783f27babb 138 key6Stat=0;
MayaMardini 0:ce783f27babb 139 key7Stat=0;
MayaMardini 0:ce783f27babb 140 key8Stat=0;
MayaMardini 0:ce783f27babb 141 key9Stat=0;
MayaMardini 0:ce783f27babb 142 key10Stat=0;
MayaMardini 0:ce783f27babb 143 key11Stat=0;
MayaMardini 0:ce783f27babb 144 key12Stat=0;
MayaMardini 0:ce783f27babb 145 key13Stat=0;
MayaMardini 0:ce783f27babb 146
MayaMardini 0:ce783f27babb 147 }
MayaMardini 0:ce783f27babb 148 }
MayaMardini 0:ce783f27babb 149 }