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