Getting input from keyboard to output on Matrix
hey guys, quite new arduino stuff , have never done programming in c. trying input keyboard, save array of chars , output array 8*8 matrix led. have combined code of previous people of keyboard , displaying message on matrix led - found on arduino website.
i have tried many ways including trying save serial.read array still not luck outputing it, wonder if can @ code , see going wrong. appreciated
i have tried many ways including trying save serial.read array still not luck outputing it, wonder if can @ code , see going wrong. appreciated

code: [select]
#include "ps2.h"
#define ps2_kc_bksp 0x08
#define ps2_kc_up 0x81
#define ps2_kc_down 0x82
#define ps2_kc_left 0x83
#define ps2_kc_right 0x84
#define ps2_kc_pgdn 0x85
#define ps2_kc_pgup 0x86
#define ps2_kc_end 0x87
#define ps2_kc_home 0x88
#define ps2_kc_ins 0x89
#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 ps2 data pin, pin 3 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 repeat each frame
int pausedelay = 500; //microseconds leave each row on before moving next
char requeststring[] = ""; //the string display
int index = 0; //this current charachter in string being displayed
int offset = 0; //this how many columns offset by
//pin definitions
int rowa[] ={11,14,16,18,13,5,7,9}; //5,6,7,8,9,10,11,12 of matrix
//(rows common anode (drive high))
int cola[] = {8,6,4,19,17,15,12,10}; //24,23,22,21,4,3,2,1 of matrix
//(columns common cathode (drive low))
//constants defining each charachters position in array of integer arrays
//letters
const int = 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 = 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;
//the array used hold bitmap of display
//(if wish other scrolling marque change data in this
//variable display)
byte data[] = {0,0,0,0,0,0,0,0};
//the alphabet
//each charachter 8 x 7 bitmap 1 on , 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,
part 2:
code: [select]
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 bitmap charachters array (each charachters position corresponds defined index (ie _a (a's bitmap)
//is @ index 0 , = 0 letters[a] return '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 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 ack byte
kbd.write(val); // send data
}
byte lookupcode() {
byte result = ps2keyboard_charbuffer;
// use switch code character conversion.
// fast , uses 4 bytes per simple line
switch (result) {
case 0x1c: result = a; break;
case 0x32: result = b; break;
case 0x21: result = c; break;
case 0x23: result = 'd'; break;
case 0x24: result = 'e'; break;
case 0x2b: result = 'f'; break;
case 0x34: result = 'g'; break;
case 0x33: result = 'h'; break;
case 0x43: result = 'i'; break;
case 0x3b: result = 'j'; break;
case 0x42: result = 'k'; break;
case 0x4b: result = 'l'; break;
case 0x3a: result = 'm'; break;
case 0x31: result = 'n'; break;
case 0x44: result = 'o'; break;
case 0x4d: result = 'p'; break;
case 0x15: 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 0x22: result = 'x'; break;
case 0x35: result = 'y'; break;
case 0x1a: result = 'z'; break;
default: delay(500); // wait bit in case part way through shift
ps2keyboard_shift = false;
ps2keyboard_ctrl = false;
ps2keyboard_alt = false;
ps2keyboard_extend = false;
ps2keyboard_release = false;
ps2keyboard_caps_lock = false;
ps2keyboard_charbuffer = 0;
}
return(result);
}
void kbd_init()
{
char ack;
kbd.write(0xff); // send reset code
ack = kbd.read(); // byte, kbd self test
ack = kbd.read(); // ack when self test done
}
void setup()
{
serial.begin(9600);
kbd_init();
code = kbd.read();
for(int = 0; <8; i++){ //set 16 pins used control array outputs
pinmode(rowa[i], output);
pinmode(cola[i], output);
}
/*
* keycode kbd , report the
* host via serial line.
*/
}
void key()
{code = kbd.read();
// updatematrix();
if( !code ) return;
// ignore null bytes
// convert scan code
switch (code) {
case 0xf0: { // key release char
ps2keyboard_release = true;
ps2keyboard_extend = false;
break;
}
case 0xfa: { // command acknowlegde byte
cmd_ack_byte_ok = true;
Arduino Forum > Forum 2005-2010 (read only) > Software > Syntax & Programs > Getting input from keyboard to output on Matrix
arduino
Comments
Post a Comment