new keypad
[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
5
6#include <ps2dev.h>
7
8PS2dev keyboard(19, 18); //clock, data
9
10#include <LedControl.h>
11
12LedControl lc=LedControl(16,14,15,2); //datain, clk, load, number of chips
7e869036 13unsigned char dispbuf[32];
ed57d028
TM
14
15#include <Keypad.h>
16
17int keyledPin = 3;
18
19const byte ROWS = 4; //four rows
20const byte COLS = 3; //four columns
21//define the cymbols on the buttons of the keypads
22char hexaKeys[ROWS][COLS] = {
23 {'1','2','3'},
24 {'4','5','6'},
25 {'7','8','9'},
26 {'*','0','#'}
27};
28byte rowPins[ROWS] = {10, 9, 8, 7}; //connect to the row pinouts of the keypad
29byte colPins[COLS] = {4, 5, 6}; //connect to the column pinouts of the keypad
30
31//initialize an instance of class NewKeypad
32Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
33
7e869036
TM
34char scancodes[] = {0x45, 0x16, 0x1E, 0x26, 0x25, 0x2E, 0x36, 0x3D, 0x3E, 0x46, 0x7C, 0x7C}; //Scancodes for numbers 0-9, *, #
35
36void cleardisp(char val) {
37 for(int i = 0; i<8; i++) dispbuf[i] = val;
ed57d028
TM
38}
39
7e869036
TM
40void 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
48void 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
61void 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}
ed57d028 73
ed57d028 74
7e869036
TM
75void setup(){
76 /*
ed57d028
TM
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);
7e869036
TM
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);
ed57d028
TM
97}
98
99void loop(){
7e869036
TM
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
ed57d028
TM
107 char customKey = customKeypad.getKey();
108
109 if (customKey){
110 Serial.println(customKey);
7e869036
TM
111 //analogWrite(keyledPin, random(0, 255));
112 analogWrite(keyledPin, 255);
ed57d028
TM
113 unsigned char numkey = customKey-0x30;
114 if(numkey < 10) {
7e869036
TM
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);
ed57d028
TM
124 }
125 }
126
7e869036
TM
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
ed57d028 138 if (customKey == '#') {
7e869036 139 keyboard.keyboard_mkbrk(0x5A); //enter
ed57d028
TM
140 }
141}
This page took 0.188283 seconds and 4 git commands to generate.