SlideShare a Scribd company logo
1 of 13
Check out for the (long) code after the break.

#include "ps2.h"

#define PS2_KC_BKSP 0×08
#define PS2_KC_UP 0×81
#define PS2_KC_DOWN 0×82
#define PS2_KC_LEFT 0×83
#define PS2_KC_RIGHT 0×84
#define PS2_KC_PGDN 0×85
#define PS2_KC_PGUP 0×86
#define PS2_KC_END 0×87
#define PS2_KC_HOME 0×88
#define PS2_KC_INS 0×89
#define PS2_KC_DEL 0x8A
#define PS2_KC_ESC 0x8B
#define PS2_KC_CLON 0x8C // caps_lock on
#define PS2_KC_CLOFF 0x8D // caps_lock off

/*
* Pin 2 is the ps2 data pin, pin 3 is the clock pin
*/

PS2 kbd(3, 2);
bool ps2Keyboard_release = false;
bool ps2Keyboard_extend = false;
bool cmd_ack_byte_ok = false;
bool ps2Keyboard_shift = false;
bool ps2Keyboard_alt = false;
bool ps2Keyboard_caps_lock = false;
bool ps2Keyboard_ctrl = false;

byte ps2Keyboard_CharBuffer = 0;

byte code;

int count = 0;

int speed = 20; //number of times to repeat each frame
int pauseDelay = 500; //microseconds to leave each row on before moving to the next

//byte result = ps2Keyboard_CharBuffer;
char incomingByte;
//char str1[] = ” “;

char requestString[100];//The string to display
char character; //to change the message in code you right yourself simply
//change this data and reset index and offset to 0
//Variables used for scrolling (both start at 0
int index = 0; //this is the current charachter in the string being displayed
int offset = 0; //this is how many columns it is offset by

//Pin Definitions
int rowA[] ={11,14,16,18,13,5,7,9}; //5,6,7,8,9,10,11,12 of matrix
//{11,14,16,18,3,5,7,9};//An Array defining which pin each row is attached to
//(rows are common anode (drive HIGH))
int colA[] = {8,6,4,19,17,15,12,10}; //24,23,22,21,4,3,2,1 of matrix
//{10,12,15,17,2,4,6,8}; //An Array defining which pin each column is attached to
//(columns are common cathode (drive LOW))

//Constants defining each charachters position in an array of integer arrays
//Letters
const int A = 0; const int B = 1; const int C = 2; const int D = 3; const int E = 4;
const int F = 5; const int G = 6; const int H = 7; const int I = 8; const int J = 9;
const int K = 10; const int L =11; const int M = 12; const int N = 13; const int O = 14;
const int P = 15; const int Q =16; const int R = 17; const int S = 18; const int T = 19;
const int U = 20; const int V =21; const int W = 22; const int X = 23; const int Y = 24;
const int Z = 25;

//Punctuation
const int COL =26; const int DASH = 27; const int BRA2 = 28; const int _ = 29; const int
LINE = 34;
const int DOT =36;

//Extra Charchters
const int FULL =30; const int CHECK = 31; const int A3 = 32; const int TEMP = 33;
const int SMILE =35; const int COLDOT = 36;

//char requestString[] = “”;
//The array used to hold a bitmap of the display
//(if you wish to do something other than scrolling marque change the data in this
//variable then display)
byte data[] = {0,0,0,0,0,0,0,0};

//The alphabet
//Each Charachter is an 8 x 7 bitmap where 1 is on and 0 if off
const int _A[] = {B0001000,
B0010100,
B0100010,
B1000001,
B1111111,
B1000001,
B1000001,
B0000000};

const int _B[] = {B1111110,
B0100001,
B0100001,
B0111110,
B0100001,
B0100001,
B1111110,
B0000000};

const int _C[] = {B0011111,
B0100000,
B1000000,
B1000000,
B1000000,
B0100000,
B0011111,
B0000000};

const int _D[] = {B1111100,
B0100010,
B0100001,
B0100001,
B0100001,
B0100010,
B1111100,
B0000000};

const int _E[] = {B1111111,
B1000000,
B1000000,
B1111100,
B1000000,
B1000000,
B1111111,
B0000000};

const int _F[] = {B1111111,
B1000000,
B1000000,
B1111100,
B1000000,
B1000000,
B1000000,
B0000000};

const int _G[] = {B0011111,
B0100000,
B1000000,
B1001111,
B1000001,
B0100001,
B0011111,
B0000000};

const int _H[] = {B1000001,
B1000001,
B1000001,
B1111111,
B1000001,
B1000001,
B1000001,
B0000000};

const int _I[] = {B1111111,
B0001000,
B0001000,
B0001000,
B0001000,
B0001000,
B1111111,
B0000000};

const int _J[] = {B0001111,
B0000001,
B0000001,
B0000001,
B0000001,
B1000001,
B0111110,
B0000000};

const int _K[] = {B1000011,
B1000100,
B1001000,
B1110000,
B1001000,
B1000100,
B1000011,
B0000000};

const int _L[] = {B1000000,
B1000000,
B1000000,
B1000000,
B1000000,
B1000000,
B1111111,
B0000000};

const int _M[] = {B1110110,
B1001001,
B1001001,
B1001001,
B1001001,
B1001001,
B1001001,
B0000000};

const int _N[] = {B1000001,
B1100001,
B1010001,
B1001001,
B1000101,
B1000011,
B1000001,
B0000000};

const int _O[] = {B0011100,
B0100010,
B1000001,
B1001001,
B1000001,
B0100010,
B0011100,
B0000000};

const int _P[] = {B1111110,
B0100001,
B0100001,
B0111110,
B0100000,
B0100000,
B0100000,
B0000000};

const int _Q[] = {B0011100,
B0100010,
B1000001,
B1000001,
B1000101,
B0100010,
B0011101,
B0000000};

const int _R[] = {B1111110,
B0100001,
B0100001,
B0101110,
B0100100,
B0100010,
B0100001,
B0000000};

const int _S[] = {B0111111,
B1000000,
B1000000,
B0111110,
B0000001,
B0000001,
B1111110,
B0000000};

const int _T[] = {B1111111,
B0001000,
B0001000,
B0001000,
B0001000,
B0001000,
B0001000,
B0000000};

const int _U[] = {B1000001,
B1000001,
B1000001,
B1000001,
B1000001,
B1000001,
B0111110,
B0000000};

const int _V[] = {B1000001,
B1000001,
B1000001,
B1000001,
B0100010,
B0010100,
B0001000,
B0000000};

const int _W[] = {B1000001,
B1001001,
B1001001,
B1001001,
B1001001,
B1001001,
B0110110,
B0000000};

const int _X[] = {B1000001,
B0100010,
B0010100,
B0001000,
B0010100,
B0100010,
B1000001,
B0000000};

const int _Y[] = {B1000001,
B0100010,
B0010100,
B0001000,
B0001000,
B0001000,
B0001000,
B0000000};

const int _Z[] = {B1111111,
B0000010,
B0000100,
B0111110,
B0010000,
B0100000,
B1111111,
B0000000};

const int _COL[] = {B0000000,
B0011000,
B0011000,
B0000000,
B0011000,
B0011000,
B0000000,
B0000000};

const int _DASH[] = {B0000000,
B0000000,
B0000000,
B0111110,
B0000000,
B0000000,
B0000000,
B0000000};

const int _BRA2[] = {B0010000,
B0001000,
B0000100,
B0000100,
B0001000,
B0010000,
B0000000,
B0000000};

const int __[] = {B0000000,
B0000000,
B0000000,
B0000000,
B0000000,
B0000000,
B0000000,
B0000000};

const int _FULL[] = {B1111111,
B1111111,
B1111111,
B1111111,
B1111111,
B1111111,
B1111111,
B0000000};

const int _CHECK[] = {B1010101,
B0101010,
B1010101,
B0101010,
B1010101,
B0101010,
B1010101,
B0000000};

const int _A3[] = {B0111110,
B0000001,
B0000001,
B0001111,
B0000001,
B1000001,
B0111110,
B0000000};

const int _TEMP[] = {B0000011,
B0011111,
B0111111,
B1111110,
B1111111,
B0011111,
B0000011,
B0000000};

const int _LINE[] = {B0000001,
B0000001,
B0000001,
B0000001,
B0000001,
B0000001,
B0000001,
B0000000};

const int _SMILE[] = {B1100110,
B1100110,
B0000000,
B0011100,
B1000001,
B0100010,
B0011100,
B0000000};

const int _DOT[] = {B0000000,
B0000000,
B0000000,
B0000000,
B1100000,
B1100000,
B0000000,
B0000000};

const int _COLDOT[] = {B0000000,
B0110000,
B0110000,
B0000000,
B0110011,
B0110011,
B0000000,
B0000000};

//Load the bitmap charachters into an array (each charachters position corresponds to its
previously defined index (ie _A (a’s bitmap)
//is at index 0 and A = 0 so letters[A] will return the ‘A’ bitmap)
const int* letters[] =
{_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,_COL,_DASH,_BRA2,__, _FULL, _CHECK, _A3, _TEMP, _LINE, _SMILE,
_DOT, _COLDOT};

//Setup runs once when power is applied

// val : bit_2=caps_lock, bit_1=num_lock, bit_0=scroll_lock
void kbd_set_lights(byte val) {
kbd.write(0xED);
kbd.read(); // pull out the ack byte
kbd.write(val); // now send the data
}

byte lookupCode() {
byte result = ps2Keyboard_CharBuffer;

// Use a switch for the code to character conversion.
// This is fast and actually only uses 4 bytes per simple line
switch (result) {
case 0x1C: result = ‘a’; break;
case 0×32: result = ‘b’; break;
case 0×21: result = ‘c’; break;
case 0×23: result = ‘d’; break;
case 0×24: result = ‘e’; break;
case 0x2B: result = ‘f’; break;
case 0×34: result = ‘g’; break;
case 0×33: result = ‘h’; break;
case 0×43: result = ‘i’; break;
case 0x3B: result = ‘j’; break;
case 0×42: result = ‘k’; break;
case 0x4B: result = ‘l’; break;
case 0x3A: result = ‘m’; break;
case 0×31: result = ‘n’; break;
case 0×44: result = ‘o’; break;
case 0x4D: result = ‘p’; break;
case 0×15: result = ‘q’; break;
case 0x2D: result = ‘r’; break;
case 0x1B: result = ‘s’; break;
case 0x2C: result = ‘t’; break;
case 0x3C: result = ‘u’; break;
case 0x2A: result = ‘v’; break;
case 0x1D: result = ‘w’; break;
case 0×22: result = ‘x’; break;
case 0×35: result = ‘y’; break;
case 0x1A: result = ‘z’; break;
case 0×29: result = ‘ ‘; break;

// Reset the shift counter for unexpected values, to get back into sync
// This allows for hot plugging a keyboard in and out
default: delay(500); // but wait a bit in case part way through a shift
ps2Keyboard_shift = false;
ps2Keyboard_ctrl = false;
ps2Keyboard_alt = false;
ps2Keyboard_extend = false;
ps2Keyboard_release = false;
ps2Keyboard_caps_lock = false;
} // end switch(result)

// done with the character
ps2Keyboard_CharBuffer = 0;
return(result);
}
int getChar(char lookupCode){
int returnValue = _;
switch(lookupCode){
case ‘A’: returnValue = A; break;
case ‘a’: returnValue = A; break;
case ‘B’: returnValue = B; break;
case ‘b’: returnValue = B; break;
case ‘C’: returnValue = C; break;
case ‘c’: returnValue = C; break;
case ‘D’: returnValue = D; break;
case ‘d’: returnValue = D; break;
case ‘E’: returnValue = E; break;
case ‘e’: returnValue = E; break;
case ‘F’: returnValue = F; break;
case ‘f’: returnValue = F; break;
case ‘G’: returnValue = G; break;
case ‘g’: returnValue = G; break;
case ‘H’: returnValue = H; break;
case ‘h’: returnValue = H; break;
case ‘I’: returnValue = I; break;
case ‘i’: returnValue = I; break;
case ‘J’: returnValue = J; break;
case ‘j’: returnValue = J; break;
case ‘K’: returnValue = K; break;
case ‘k’: returnValue = K; break;
case ‘L’: returnValue = L; break;
case ‘l’: returnValue = L; break;
case ‘M’: returnValue = M; break;
case ‘m’: returnValue = M; break;
case ‘N’: returnValue = N; break;
case ‘n’: returnValue = N; break;
case ‘O’: returnValue = O; break;
case ‘o’: returnValue = O; break;
case ‘P’: returnValue = P; break;
case ‘p’: returnValue = P; break;
case ‘Q’: returnValue = Q; break;
case ‘q’: returnValue = Q; break;
case ‘R’: returnValue = R; break;
case ‘r’: returnValue = R; break;
case ‘S’: returnValue = S; break;
case ‘s’: returnValue = S; break;
case ‘T’: returnValue = T; break;
case ‘t’: returnValue = T; break;
case ‘U’: returnValue = U; break;
case ‘u’: returnValue = U; break;
case ‘V’: returnValue = V; break;
case ‘v’: returnValue = V; break;
case ‘W’: returnValue = W; break;
case ‘w’: returnValue = W; break;
case ‘X’: returnValue = X; break;
case ‘x’: returnValue = X; break;
case ‘Y’: returnValue = Y; break;
case ‘y’: returnValue = Y; break;
case ‘Z’: returnValue = Z; break;
case ‘z’: returnValue = Z; break;
case ‘ ‘: returnValue = _; break;
case ’3′: returnValue = A3; break;
case ‘<’: returnValue = TEMP; break; case ‘*’: returnValue = FULL; break; case ”:
returnValue = LINE; break; case ‘_’: returnValue = _; break; case ‘:’: returnValue =
COL; break; case ‘-’: returnValue = DASH; break; case ‘)’: returnValue = BRA2; break;
case ‘%’: returnValue = SMILE; break; case ‘.’: returnValue = DOT; break; case ‘^’:
returnValue = COLDOT; break; } return returnValue; } void kbd_init() { char ack;
kbd.write(0xff); // send reset code ack = kbd.read(); // byte, kbd does self test ack =
kbd.read(); // another ack when self test is done } void setup() { Serial.begin(9600);
kbd_init(); code = kbd.read(); for(int i = 0; i <8; code =” kbd.read();”
ps2keyboard_release =” true;” ps2keyboard_extend =” false;” cmd_ack_byte_ok =”
true;” ps2keyboard_extend =” true;” ps2keyboard_shift =” ps2Keyboard_release?”
ps2keyboard_release =” false;” ps2keyboard_alt =” ps2Keyboard_release?”
ps2keyboard_release =” false;” ps2keyboard_ctrl =” ps2Keyboard_release?”
ps2keyboard_release =” false;” ps2keyboard_caps_lock =” ps2Keyboard_caps_lock?”
ps2keyboard_release =” false;” ps2keyboard_release =” false;” ps2keyboard_charbuffer
=” code;” i =”0;” currentchar =” getChar(requestString[index]);” nextchar =”
getChar(requestString[index+1]);” row=”0;” column=”0;”>> (8-offset) )); //loads the
next charachter offset by offset pixels
}
}
offset++; //increment the offset by one row
if(offset==8){offset = 0; index++; if(index==sizeof(requestString)-2){index=0;}} //if
offset is 8 load the next charachter pair for the next time through
}

void showSprite(int speed2){
for(int iii = 0; iii < column =” 0;” i =” 0;” i =” 0;” i =”=” row =” 0;” bit =”
(data[column]“>> row) & 1;
if(bit == 1){
digitalWrite(rowA[row], HIGH); //if the bit in the data array is set turn the LED on
}

}
delayMicroseconds(pauseDelay); //leave the column on for pauseDelay microseconds
(too high a delay causes flicker)
}
}

More Related Content

What's hot

Arduino coding class part ii
Arduino coding class part iiArduino coding class part ii
Arduino coding class part iiJonah Marrs
 
Arduino coding class
Arduino coding classArduino coding class
Arduino coding classJonah Marrs
 
Алексей Кутумов, Вектор с нуля
Алексей Кутумов, Вектор с нуляАлексей Кутумов, Вектор с нуля
Алексей Кутумов, Вектор с нуляSergey Platonov
 
Standford 2015 week3: Objective-C Compatibility, Property List, Views
Standford 2015 week3: Objective-C Compatibility, Property List, ViewsStandford 2015 week3: Objective-C Compatibility, Property List, Views
Standford 2015 week3: Objective-C Compatibility, Property List, Views彼得潘 Pan
 

What's hot (10)

OpenGL ES 3 Reference Card
OpenGL ES 3 Reference CardOpenGL ES 3 Reference Card
OpenGL ES 3 Reference Card
 
Arduino coding class part ii
Arduino coding class part iiArduino coding class part ii
Arduino coding class part ii
 
Code em Poker
Code em PokerCode em Poker
Code em Poker
 
Arduino coding class
Arduino coding classArduino coding class
Arduino coding class
 
OpenGL 4.4 Reference Card
OpenGL 4.4 Reference CardOpenGL 4.4 Reference Card
OpenGL 4.4 Reference Card
 
OpenGL ES 3.2 Reference Guide
OpenGL ES 3.2 Reference GuideOpenGL ES 3.2 Reference Guide
OpenGL ES 3.2 Reference Guide
 
Алексей Кутумов, Вектор с нуля
Алексей Кутумов, Вектор с нуляАлексей Кутумов, Вектор с нуля
Алексей Кутумов, Вектор с нуля
 
Pre zen ta sion
Pre zen ta sionPre zen ta sion
Pre zen ta sion
 
OpenVX 1.2 Reference Guide
OpenVX 1.2 Reference GuideOpenVX 1.2 Reference Guide
OpenVX 1.2 Reference Guide
 
Standford 2015 week3: Objective-C Compatibility, Property List, Views
Standford 2015 week3: Objective-C Compatibility, Property List, ViewsStandford 2015 week3: Objective-C Compatibility, Property List, Views
Standford 2015 week3: Objective-C Compatibility, Property List, Views
 

Viewers also liked

Fort Brave - Złote myśli ze szkoleń
Fort Brave - Złote myśli ze szkoleńFort Brave - Złote myśli ze szkoleń
Fort Brave - Złote myśli ze szkoleńLeadershipCenter
 
Fort Brave - Pełne doświadczenie projektu w 2 dni
Fort Brave - Pełne doświadczenie projektu w 2 dniFort Brave - Pełne doświadczenie projektu w 2 dni
Fort Brave - Pełne doświadczenie projektu w 2 dniLeadershipCenter
 
Mmabatho201120558
Mmabatho201120558Mmabatho201120558
Mmabatho201120558NozzyM
 
Mm project data visualization-finalized
Mm project  data visualization-finalizedMm project  data visualization-finalized
Mm project data visualization-finalizedchangming yang
 
Mistrzowie rzeczy oczywistych
Mistrzowie rzeczy oczywistychMistrzowie rzeczy oczywistych
Mistrzowie rzeczy oczywistychLeadershipCenter
 
Creative class portfolio
Creative class portfolioCreative class portfolio
Creative class portfoliochangming yang
 
Pracuj z pasją - Zyj swoim życiem, to ty decydujesz
Pracuj z pasją  - Zyj swoim życiem, to ty decydujeszPracuj z pasją  - Zyj swoim życiem, to ty decydujesz
Pracuj z pasją - Zyj swoim życiem, to ty decydujeszLeadershipCenter
 
Leadership Center - prezentacja firmy Pecha Kucha
Leadership Center - prezentacja firmy Pecha KuchaLeadership Center - prezentacja firmy Pecha Kucha
Leadership Center - prezentacja firmy Pecha KuchaLeadershipCenter
 
How much a brand worth
How much a brand worthHow much a brand worth
How much a brand worthchangming yang
 
25022013 siska ryane mpmt
25022013 siska ryane mpmt25022013 siska ryane mpmt
25022013 siska ryane mpmtsiskaryane
 

Viewers also liked (15)

Fort Brave - Złote myśli ze szkoleń
Fort Brave - Złote myśli ze szkoleńFort Brave - Złote myśli ze szkoleń
Fort Brave - Złote myśli ze szkoleń
 
Fort Brave - Pełne doświadczenie projektu w 2 dni
Fort Brave - Pełne doświadczenie projektu w 2 dniFort Brave - Pełne doświadczenie projektu w 2 dni
Fort Brave - Pełne doświadczenie projektu w 2 dni
 
Interests
InterestsInterests
Interests
 
Mmabatho201120558
Mmabatho201120558Mmabatho201120558
Mmabatho201120558
 
Mm project data visualization-finalized
Mm project  data visualization-finalizedMm project  data visualization-finalized
Mm project data visualization-finalized
 
CMS and Joomla
CMS and JoomlaCMS and Joomla
CMS and Joomla
 
Mistrzowie rzeczy oczywistych
Mistrzowie rzeczy oczywistychMistrzowie rzeczy oczywistych
Mistrzowie rzeczy oczywistych
 
Creative class portfolio
Creative class portfolioCreative class portfolio
Creative class portfolio
 
Pracuj z pasją - Zyj swoim życiem, to ty decydujesz
Pracuj z pasją  - Zyj swoim życiem, to ty decydujeszPracuj z pasją  - Zyj swoim życiem, to ty decydujesz
Pracuj z pasją - Zyj swoim życiem, to ty decydujesz
 
Leadership Center - prezentacja firmy Pecha Kucha
Leadership Center - prezentacja firmy Pecha KuchaLeadership Center - prezentacja firmy Pecha Kucha
Leadership Center - prezentacja firmy Pecha Kucha
 
Fly ash disposal
Fly ash disposalFly ash disposal
Fly ash disposal
 
How much a brand worth
How much a brand worthHow much a brand worth
How much a brand worth
 
Code monkey ecommerce
Code monkey ecommerceCode monkey ecommerce
Code monkey ecommerce
 
25022013 siska ryane mpmt
25022013 siska ryane mpmt25022013 siska ryane mpmt
25022013 siska ryane mpmt
 
AODV Protocol
AODV ProtocolAODV Protocol
AODV Protocol
 

Similar to Arduino based keyboard and display interfacing

Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxSANTIAGO PABLO ALBERTO
 
7segment scetch
7segment scetch7segment scetch
7segment scetchBang Igo
 
implemement the game.cpp by the header file given. And create main.c.pdf
implemement the game.cpp by the header file given. And create main.c.pdfimplemement the game.cpp by the header file given. And create main.c.pdf
implemement the game.cpp by the header file given. And create main.c.pdffazilfootsteps
 
Codigo fuente
Codigo fuenteCodigo fuente
Codigo fuenteBlackD10
 
C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxssuser3cbb4c
 
Digital Voltmeter displaying voltage level on a seven segment display and com...
Digital Voltmeter displaying voltage level on a seven segment display and com...Digital Voltmeter displaying voltage level on a seven segment display and com...
Digital Voltmeter displaying voltage level on a seven segment display and com...Karthik Rathinavel
 
Radix 2 code
Radix 2 codeRadix 2 code
Radix 2 codepradipakv
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...ssuserd6b1fd
 
a) In the code, board is initialized by reading an input file. But y.pdf
a) In the code, board is initialized by reading an input file. But y.pdfa) In the code, board is initialized by reading an input file. But y.pdf
a) In the code, board is initialized by reading an input file. But y.pdfanuradhasilks
 
How do I modify this code in order to create a rotating pyramid instea.pdf
How do I modify this code in order to create a rotating pyramid instea.pdfHow do I modify this code in order to create a rotating pyramid instea.pdf
How do I modify this code in order to create a rotating pyramid instea.pdfkrishnac481
 
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019corehard_by
 
The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IOT Academy
 

Similar to Arduino based keyboard and display interfacing (20)

Microcontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docxMicrocontroladores: programas de CCS Compiler.docx
Microcontroladores: programas de CCS Compiler.docx
 
FINISHED_CODE
FINISHED_CODEFINISHED_CODE
FINISHED_CODE
 
7segment scetch
7segment scetch7segment scetch
7segment scetch
 
implemement the game.cpp by the header file given. And create main.c.pdf
implemement the game.cpp by the header file given. And create main.c.pdfimplemement the game.cpp by the header file given. And create main.c.pdf
implemement the game.cpp by the header file given. And create main.c.pdf
 
PIC and LCD
PIC and LCDPIC and LCD
PIC and LCD
 
Codigo fuente
Codigo fuenteCodigo fuente
Codigo fuente
 
VERILOG CODE
VERILOG CODEVERILOG CODE
VERILOG CODE
 
DataTypes.ppt
DataTypes.pptDataTypes.ppt
DataTypes.ppt
 
C++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptxC++ lectures all chapters in one slide.pptx
C++ lectures all chapters in one slide.pptx
 
Digital Voltmeter displaying voltage level on a seven segment display and com...
Digital Voltmeter displaying voltage level on a seven segment display and com...Digital Voltmeter displaying voltage level on a seven segment display and com...
Digital Voltmeter displaying voltage level on a seven segment display and com...
 
Radix 2 code
Radix 2 codeRadix 2 code
Radix 2 code
 
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
Notes for C Programming for MCA, BCA, B. Tech CSE, ECE and MSC (CS) 2 of 5 by...
 
mod-4.pptx
mod-4.pptxmod-4.pptx
mod-4.pptx
 
a) In the code, board is initialized by reading an input file. But y.pdf
a) In the code, board is initialized by reading an input file. But y.pdfa) In the code, board is initialized by reading an input file. But y.pdf
a) In the code, board is initialized by reading an input file. But y.pdf
 
Bit manipulation
Bit manipulationBit manipulation
Bit manipulation
 
An Example MIPS
An Example  MIPSAn Example  MIPS
An Example MIPS
 
How do I modify this code in order to create a rotating pyramid instea.pdf
How do I modify this code in order to create a rotating pyramid instea.pdfHow do I modify this code in order to create a rotating pyramid instea.pdf
How do I modify this code in order to create a rotating pyramid instea.pdf
 
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
Как работает LLVM бэкенд в C#. Егор Богатов ➠ CoreHard Autumn 2019
 
Interpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratchInterpreter, Compiler, JIT from scratch
Interpreter, Compiler, JIT from scratch
 
The IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programmingThe IoT Academy IoT Training Arduino Part 3 programming
The IoT Academy IoT Training Arduino Part 3 programming
 

Arduino based keyboard and display interfacing

  • 1. Check out for the (long) code after the break. #include "ps2.h" #define PS2_KC_BKSP 0×08 #define PS2_KC_UP 0×81 #define PS2_KC_DOWN 0×82 #define PS2_KC_LEFT 0×83 #define PS2_KC_RIGHT 0×84 #define PS2_KC_PGDN 0×85 #define PS2_KC_PGUP 0×86 #define PS2_KC_END 0×87 #define PS2_KC_HOME 0×88 #define PS2_KC_INS 0×89 #define PS2_KC_DEL 0x8A #define PS2_KC_ESC 0x8B #define PS2_KC_CLON 0x8C // caps_lock on #define PS2_KC_CLOFF 0x8D // caps_lock off /* * Pin 2 is the ps2 data pin, pin 3 is the clock pin */ PS2 kbd(3, 2); bool ps2Keyboard_release = false; bool ps2Keyboard_extend = false; bool cmd_ack_byte_ok = false; bool ps2Keyboard_shift = false; bool ps2Keyboard_alt = false; bool ps2Keyboard_caps_lock = false; bool ps2Keyboard_ctrl = false; byte ps2Keyboard_CharBuffer = 0; byte code; int count = 0; int speed = 20; //number of times to repeat each frame int pauseDelay = 500; //microseconds to leave each row on before moving to the next //byte result = ps2Keyboard_CharBuffer; char incomingByte; //char str1[] = ” “; char requestString[100];//The string to display
  • 2. char character; //to change the message in code you right yourself simply //change this data and reset index and offset to 0 //Variables used for scrolling (both start at 0 int index = 0; //this is the current charachter in the string being displayed int offset = 0; //this is how many columns it is offset by //Pin Definitions int rowA[] ={11,14,16,18,13,5,7,9}; //5,6,7,8,9,10,11,12 of matrix //{11,14,16,18,3,5,7,9};//An Array defining which pin each row is attached to //(rows are common anode (drive HIGH)) int colA[] = {8,6,4,19,17,15,12,10}; //24,23,22,21,4,3,2,1 of matrix //{10,12,15,17,2,4,6,8}; //An Array defining which pin each column is attached to //(columns are common cathode (drive LOW)) //Constants defining each charachters position in an array of integer arrays //Letters const int A = 0; const int B = 1; const int C = 2; const int D = 3; const int E = 4; const int F = 5; const int G = 6; const int H = 7; const int I = 8; const int J = 9; const int K = 10; const int L =11; const int M = 12; const int N = 13; const int O = 14; const int P = 15; const int Q =16; const int R = 17; const int S = 18; const int T = 19; const int U = 20; const int V =21; const int W = 22; const int X = 23; const int Y = 24; const int Z = 25; //Punctuation const int COL =26; const int DASH = 27; const int BRA2 = 28; const int _ = 29; const int LINE = 34; const int DOT =36; //Extra Charchters const int FULL =30; const int CHECK = 31; const int A3 = 32; const int TEMP = 33; const int SMILE =35; const int COLDOT = 36; //char requestString[] = “”; //The array used to hold a bitmap of the display //(if you wish to do something other than scrolling marque change the data in this //variable then display) byte data[] = {0,0,0,0,0,0,0,0}; //The alphabet //Each Charachter is an 8 x 7 bitmap where 1 is on and 0 if off const int _A[] = {B0001000, B0010100, B0100010, B1000001, B1111111, B1000001,
  • 3. B1000001, B0000000}; const int _B[] = {B1111110, B0100001, B0100001, B0111110, B0100001, B0100001, B1111110, B0000000}; const int _C[] = {B0011111, B0100000, B1000000, B1000000, B1000000, B0100000, B0011111, B0000000}; const int _D[] = {B1111100, B0100010, B0100001, B0100001, B0100001, B0100010, B1111100, B0000000}; const int _E[] = {B1111111, B1000000, B1000000, B1111100, B1000000, B1000000, B1111111, B0000000}; const int _F[] = {B1111111, B1000000, B1000000, B1111100, B1000000, B1000000,
  • 4. B1000000, B0000000}; const int _G[] = {B0011111, B0100000, B1000000, B1001111, B1000001, B0100001, B0011111, B0000000}; const int _H[] = {B1000001, B1000001, B1000001, B1111111, B1000001, B1000001, B1000001, B0000000}; const int _I[] = {B1111111, B0001000, B0001000, B0001000, B0001000, B0001000, B1111111, B0000000}; const int _J[] = {B0001111, B0000001, B0000001, B0000001, B0000001, B1000001, B0111110, B0000000}; const int _K[] = {B1000011, B1000100, B1001000, B1110000, B1001000, B1000100,
  • 5. B1000011, B0000000}; const int _L[] = {B1000000, B1000000, B1000000, B1000000, B1000000, B1000000, B1111111, B0000000}; const int _M[] = {B1110110, B1001001, B1001001, B1001001, B1001001, B1001001, B1001001, B0000000}; const int _N[] = {B1000001, B1100001, B1010001, B1001001, B1000101, B1000011, B1000001, B0000000}; const int _O[] = {B0011100, B0100010, B1000001, B1001001, B1000001, B0100010, B0011100, B0000000}; const int _P[] = {B1111110, B0100001, B0100001, B0111110, B0100000, B0100000,
  • 6. B0100000, B0000000}; const int _Q[] = {B0011100, B0100010, B1000001, B1000001, B1000101, B0100010, B0011101, B0000000}; const int _R[] = {B1111110, B0100001, B0100001, B0101110, B0100100, B0100010, B0100001, B0000000}; const int _S[] = {B0111111, B1000000, B1000000, B0111110, B0000001, B0000001, B1111110, B0000000}; const int _T[] = {B1111111, B0001000, B0001000, B0001000, B0001000, B0001000, B0001000, B0000000}; const int _U[] = {B1000001, B1000001, B1000001, B1000001, B1000001, B1000001,
  • 7. B0111110, B0000000}; const int _V[] = {B1000001, B1000001, B1000001, B1000001, B0100010, B0010100, B0001000, B0000000}; const int _W[] = {B1000001, B1001001, B1001001, B1001001, B1001001, B1001001, B0110110, B0000000}; const int _X[] = {B1000001, B0100010, B0010100, B0001000, B0010100, B0100010, B1000001, B0000000}; const int _Y[] = {B1000001, B0100010, B0010100, B0001000, B0001000, B0001000, B0001000, B0000000}; const int _Z[] = {B1111111, B0000010, B0000100, B0111110, B0010000, B0100000,
  • 8. B1111111, B0000000}; const int _COL[] = {B0000000, B0011000, B0011000, B0000000, B0011000, B0011000, B0000000, B0000000}; const int _DASH[] = {B0000000, B0000000, B0000000, B0111110, B0000000, B0000000, B0000000, B0000000}; const int _BRA2[] = {B0010000, B0001000, B0000100, B0000100, B0001000, B0010000, B0000000, B0000000}; const int __[] = {B0000000, B0000000, B0000000, B0000000, B0000000, B0000000, B0000000, B0000000}; const int _FULL[] = {B1111111, B1111111, B1111111, B1111111, B1111111, B1111111,
  • 9. B1111111, B0000000}; const int _CHECK[] = {B1010101, B0101010, B1010101, B0101010, B1010101, B0101010, B1010101, B0000000}; const int _A3[] = {B0111110, B0000001, B0000001, B0001111, B0000001, B1000001, B0111110, B0000000}; const int _TEMP[] = {B0000011, B0011111, B0111111, B1111110, B1111111, B0011111, B0000011, B0000000}; const int _LINE[] = {B0000001, B0000001, B0000001, B0000001, B0000001, B0000001, B0000001, B0000000}; const int _SMILE[] = {B1100110, B1100110, B0000000, B0011100, B1000001, B0100010,
  • 10. B0011100, B0000000}; const int _DOT[] = {B0000000, B0000000, B0000000, B0000000, B1100000, B1100000, B0000000, B0000000}; const int _COLDOT[] = {B0000000, B0110000, B0110000, B0000000, B0110011, B0110011, B0000000, B0000000}; //Load the bitmap charachters into an array (each charachters position corresponds to its previously defined index (ie _A (a’s bitmap) //is at index 0 and A = 0 so letters[A] will return the ‘A’ bitmap) const int* letters[] = {_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,_COL,_DASH,_BRA2,__, _FULL, _CHECK, _A3, _TEMP, _LINE, _SMILE, _DOT, _COLDOT}; //Setup runs once when power is applied // val : bit_2=caps_lock, bit_1=num_lock, bit_0=scroll_lock void kbd_set_lights(byte val) { kbd.write(0xED); kbd.read(); // pull out the ack byte kbd.write(val); // now send the data } byte lookupCode() { byte result = ps2Keyboard_CharBuffer; // Use a switch for the code to character conversion. // This is fast and actually only uses 4 bytes per simple line switch (result) { case 0x1C: result = ‘a’; break; case 0×32: result = ‘b’; break;
  • 11. case 0×21: result = ‘c’; break; case 0×23: result = ‘d’; break; case 0×24: result = ‘e’; break; case 0x2B: result = ‘f’; break; case 0×34: result = ‘g’; break; case 0×33: result = ‘h’; break; case 0×43: result = ‘i’; break; case 0x3B: result = ‘j’; break; case 0×42: result = ‘k’; break; case 0x4B: result = ‘l’; break; case 0x3A: result = ‘m’; break; case 0×31: result = ‘n’; break; case 0×44: result = ‘o’; break; case 0x4D: result = ‘p’; break; case 0×15: result = ‘q’; break; case 0x2D: result = ‘r’; break; case 0x1B: result = ‘s’; break; case 0x2C: result = ‘t’; break; case 0x3C: result = ‘u’; break; case 0x2A: result = ‘v’; break; case 0x1D: result = ‘w’; break; case 0×22: result = ‘x’; break; case 0×35: result = ‘y’; break; case 0x1A: result = ‘z’; break; case 0×29: result = ‘ ‘; break; // Reset the shift counter for unexpected values, to get back into sync // This allows for hot plugging a keyboard in and out default: delay(500); // but wait a bit in case part way through a shift ps2Keyboard_shift = false; ps2Keyboard_ctrl = false; ps2Keyboard_alt = false; ps2Keyboard_extend = false; ps2Keyboard_release = false; ps2Keyboard_caps_lock = false; } // end switch(result) // done with the character ps2Keyboard_CharBuffer = 0; return(result); } int getChar(char lookupCode){ int returnValue = _; switch(lookupCode){ case ‘A’: returnValue = A; break; case ‘a’: returnValue = A; break;
  • 12. case ‘B’: returnValue = B; break; case ‘b’: returnValue = B; break; case ‘C’: returnValue = C; break; case ‘c’: returnValue = C; break; case ‘D’: returnValue = D; break; case ‘d’: returnValue = D; break; case ‘E’: returnValue = E; break; case ‘e’: returnValue = E; break; case ‘F’: returnValue = F; break; case ‘f’: returnValue = F; break; case ‘G’: returnValue = G; break; case ‘g’: returnValue = G; break; case ‘H’: returnValue = H; break; case ‘h’: returnValue = H; break; case ‘I’: returnValue = I; break; case ‘i’: returnValue = I; break; case ‘J’: returnValue = J; break; case ‘j’: returnValue = J; break; case ‘K’: returnValue = K; break; case ‘k’: returnValue = K; break; case ‘L’: returnValue = L; break; case ‘l’: returnValue = L; break; case ‘M’: returnValue = M; break; case ‘m’: returnValue = M; break; case ‘N’: returnValue = N; break; case ‘n’: returnValue = N; break; case ‘O’: returnValue = O; break; case ‘o’: returnValue = O; break; case ‘P’: returnValue = P; break; case ‘p’: returnValue = P; break; case ‘Q’: returnValue = Q; break; case ‘q’: returnValue = Q; break; case ‘R’: returnValue = R; break; case ‘r’: returnValue = R; break; case ‘S’: returnValue = S; break; case ‘s’: returnValue = S; break; case ‘T’: returnValue = T; break; case ‘t’: returnValue = T; break; case ‘U’: returnValue = U; break; case ‘u’: returnValue = U; break; case ‘V’: returnValue = V; break; case ‘v’: returnValue = V; break; case ‘W’: returnValue = W; break; case ‘w’: returnValue = W; break; case ‘X’: returnValue = X; break; case ‘x’: returnValue = X; break;
  • 13. case ‘Y’: returnValue = Y; break; case ‘y’: returnValue = Y; break; case ‘Z’: returnValue = Z; break; case ‘z’: returnValue = Z; break; case ‘ ‘: returnValue = _; break; case ’3′: returnValue = A3; break; case ‘<’: returnValue = TEMP; break; case ‘*’: returnValue = FULL; break; case ”: returnValue = LINE; break; case ‘_’: returnValue = _; break; case ‘:’: returnValue = COL; break; case ‘-’: returnValue = DASH; break; case ‘)’: returnValue = BRA2; break; case ‘%’: returnValue = SMILE; break; case ‘.’: returnValue = DOT; break; case ‘^’: returnValue = COLDOT; break; } return returnValue; } void kbd_init() { char ack; kbd.write(0xff); // send reset code ack = kbd.read(); // byte, kbd does self test ack = kbd.read(); // another ack when self test is done } void setup() { Serial.begin(9600); kbd_init(); code = kbd.read(); for(int i = 0; i <8; code =” kbd.read();” ps2keyboard_release =” true;” ps2keyboard_extend =” false;” cmd_ack_byte_ok =” true;” ps2keyboard_extend =” true;” ps2keyboard_shift =” ps2Keyboard_release?” ps2keyboard_release =” false;” ps2keyboard_alt =” ps2Keyboard_release?” ps2keyboard_release =” false;” ps2keyboard_ctrl =” ps2Keyboard_release?” ps2keyboard_release =” false;” ps2keyboard_caps_lock =” ps2Keyboard_caps_lock?” ps2keyboard_release =” false;” ps2keyboard_release =” false;” ps2keyboard_charbuffer =” code;” i =”0;” currentchar =” getChar(requestString[index]);” nextchar =” getChar(requestString[index+1]);” row=”0;” column=”0;”>> (8-offset) )); //loads the next charachter offset by offset pixels } } offset++; //increment the offset by one row if(offset==8){offset = 0; index++; if(index==sizeof(requestString)-2){index=0;}} //if offset is 8 load the next charachter pair for the next time through } void showSprite(int speed2){ for(int iii = 0; iii < column =” 0;” i =” 0;” i =” 0;” i =”=” row =” 0;” bit =” (data[column]“>> row) & 1; if(bit == 1){ digitalWrite(rowA[row], HIGH); //if the bit in the data array is set turn the LED on } } delayMicroseconds(pauseDelay); //leave the column on for pauseDelay microseconds (too high a delay causes flicker) } }