3221e78022842e047d03bfaaf4863bd103269972
[mirrors/Programs.git] / arduino / bomba-keypad / bomba-keypad.ino
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 unsigned char dispbuf[32];
14
15 #include <Keypad.h>
16
17 int keyledPin = 3;
18
19 const byte ROWS = 4; //four rows
20 const byte COLS = 3; //four columns
21 //define the cymbols on the buttons of the keypads
22 char hexaKeys[ROWS][COLS] = {
23 {'1','2','3'},
24 {'4','5','6'},
25 {'7','8','9'},
26 {'*','0','#'}
27 };
28 byte rowPins[ROWS] = {10, 9, 8, 7}; //connect to the row pinouts of the keypad
29 byte colPins[COLS] = {4, 5, 6}; //connect to the column pinouts of the keypad
30
31 //initialize an instance of class NewKeypad
32 Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
33
34 char scancodes[] = {0x45, 0x16, 0x1E, 0x26, 0x25, 0x2E, 0x36, 0x3D, 0x3E, 0x46, 0x7C, 0x7C}; //Scancodes for numbers 0-9, *, #
35
36 void cleardisp(char val) {
37 for(int i = 0; i<8; i++) dispbuf[i] = val;
38 }
39
40 void drawdisp(int shift) {
41 lc.clearDisplay(0);
42 for(int i = 0; i<8; i++) {
43 if(shift) dispbuf[i] = dispbuf[i+1];
44 if(dispbuf[i] != '_') lc.setDigit(0,7-i,dispbuf[i],false); //addr, digit, value, decimalpoint
45 }
46 }
47
48 void intro() {
49 cleardisp('_');
50 for(int i = 0; i<100; i++) {
51 analogWrite(keyledPin, i);
52 if(i >= 20*1) dispbuf[3] = dispbuf[4] = 0;
53 if(i >= 20*2) dispbuf[2] = dispbuf[5] = 0;
54 if(i >= 20*3) dispbuf[1] = dispbuf[6] = 0;
55 if(i >= 20*4) dispbuf[0] = dispbuf[7] = 0;
56 drawdisp(0);
57 delay(20);
58 }
59 }
60
61 void outro() {
62 cleardisp(0);
63 for(int i = 100; i>=0; i--) {
64 analogWrite(keyledPin, i);
65 if(i <= 20*1) dispbuf[3] = dispbuf[4] = '_';
66 if(i <= 20*2) dispbuf[2] = dispbuf[5] = '_';
67 if(i <= 20*3) dispbuf[1] = dispbuf[6] = '_';
68 if(i <= 20*4) dispbuf[0] = dispbuf[7] = '_';
69 drawdisp(0);
70 delay(20);
71 }
72 }
73
74
75 void setup(){
76 /*
77 The MAX72XX is in power-saving mode on startup,
78 we have to do a wakeup call
79 */
80 lc.shutdown(0,false);
81 /* Set the brightness to a medium values */
82 lc.setIntensity(0,15); //0 - 15
83 /* and clear the display */
84 lc.clearDisplay(0);
85
86 intro();
87 cleardisp('_'); drawdisp(0);
88
89 // send the keyboard start up
90 keyboard.keyboard_init();
91
92 Serial.begin(9600);
93
94
95
96 pinMode(LED_BUILTIN, OUTPUT);
97 }
98
99 void loop(){
100 unsigned char leds;
101 if(keyboard.keyboard_handle(&leds)) {
102 //Serial.print('LEDS');
103 //Serial.print(leds, HEX);
104 digitalWrite(LED_BUILTIN, leds);
105 }
106
107 char customKey = customKeypad.getKey();
108
109 if (customKey){
110 Serial.println(customKey);
111 //analogWrite(keyledPin, random(0, 255));
112 analogWrite(keyledPin, 255);
113 unsigned char numkey = customKey-0x30;
114 if(numkey < 10) {
115 //Send PS2
116 keyboard.keyboard_mkbrk(scancodes[numkey]);
117
118 //Single digit
119 //lc.setDigit(0,7,numkey,false); //addr, digit, value, decimalpoint
120
121 //Scroll out display
122 dispbuf[8] = numkey;
123 drawdisp(1);
124 }
125 }
126
127 if (customKey == '*') {
128 //Send PS2
129 keyboard.keyboard_mkbrk(scancodes[10]);
130
131 //analogWrite(keyledPin, 0);
132 outro();
133
134 cleardisp('_');
135 drawdisp(0);
136 }
137
138 if (customKey == '#') {
139 keyboard.keyboard_mkbrk(0x5A); //enter
140 }
141 }
This page took 0.315776 seconds and 3 git commands to generate.