Commit | Line | Data |
---|---|---|
ed57d028 TM |
1 | /* |
2 | * PS2 pinout cinskej kabel: data cerveny (18), clock bily (19), 5V cerny, GND zluty | |
3 | */ | |
4 | ||
5 | ||
6 | #include <ps2dev.h> | |
7 | ||
8 | PS2dev keyboard(19, 18); //clock, data | |
9 | ||
10 | #include <LedControl.h> | |
11 | ||
12 | LedControl lc=LedControl(16,14,15,2); //datain, clk, load, number of chips | |
13 | ||
14 | #include <Keypad.h> | |
15 | ||
16 | int keyledPin = 3; | |
17 | ||
18 | const byte ROWS = 4; //four rows | |
19 | const byte COLS = 3; //four columns | |
20 | //define the cymbols on the buttons of the keypads | |
21 | char hexaKeys[ROWS][COLS] = { | |
22 | {'1','2','3'}, | |
23 | {'4','5','6'}, | |
24 | {'7','8','9'}, | |
25 | {'*','0','#'} | |
26 | }; | |
27 | byte rowPins[ROWS] = {10, 9, 8, 7}; //connect to the row pinouts of the keypad | |
28 | byte colPins[COLS] = {4, 5, 6}; //connect to the column pinouts of the keypad | |
29 | ||
30 | //initialize an instance of class NewKeypad | |
31 | Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS); | |
32 | ||
33 | void make_break_kb(byte data) | |
34 | { | |
35 | // makes and breaks the key | |
36 | keyboard.write(data); | |
37 | delay(50); | |
38 | keyboard.write(0xF0); | |
39 | delay(50); | |
40 | keyboard.write(data); | |
41 | delay(50); | |
42 | } | |
43 | ||
44 | char scancodes[] = {0x45, 0x16, 0x1E, 0x26, 0x25, 0x2E, 0x36, 0x3D, 0x3E, 0x46, 0x7C, 0x7C}; //Scancodes for numbers 0-9, *, # | |
45 | ||
46 | void setup(){ | |
47 | Serial.begin(9600); | |
48 | ||
49 | /* | |
50 | The MAX72XX is in power-saving mode on startup, | |
51 | we have to do a wakeup call | |
52 | */ | |
53 | lc.shutdown(0,false); | |
54 | /* Set the brightness to a medium values */ | |
55 | lc.setIntensity(0,15); //0 - 15 | |
56 | /* and clear the display */ | |
57 | lc.clearDisplay(0); | |
58 | } | |
59 | ||
60 | void loop(){ | |
61 | char customKey = customKeypad.getKey(); | |
62 | ||
63 | if (customKey){ | |
64 | Serial.println(customKey); | |
65 | analogWrite(keyledPin, random(0, 255)); | |
66 | unsigned char numkey = customKey-0x30; | |
67 | if(numkey < 10) { | |
68 | lc.setDigit(0,0,numkey,false); //addr, digit, value, decimalpoint | |
69 | lc.setDigit(0,7,numkey,false); //addr, digit, value, decimalpoint | |
70 | make_break_kb(scancodes[numkey]); | |
71 | } | |
72 | } | |
73 | ||
74 | if (customKey == '#') { | |
75 | lc.clearDisplay(0); | |
76 | analogWrite(keyledPin, 0); | |
77 | make_break_kb(scancodes[10]); | |
78 | } | |
79 | } |