-
Notifications
You must be signed in to change notification settings - Fork 1
/
LCD_grafico.ino
143 lines (121 loc) · 3.64 KB
/
LCD_grafico.ino
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
#include <Keypad.h>
//#include <LiquidCrystal_I2C.h>
//#include <Wire.h>
#include "U8glib.h"
U8GLIB_ST7920_128X64_1X u8g(6, 7, 8, 9, 10, 11, 12, 13, 2, 4, 3, 5);
//LiquidCrystal_I2C lcd(0x27,16,2);
//const int rs = 8, en = 9, d4 = 4, d5 = 5, d6 = 6, d7 = 7;
//LiquidCrystal lcd(rs, en, d4, d5, d6, d7);
const byte rowsCount = 4;
const byte columsCount = 4;
char c1,c2,c3,aux,anterior,seleccionado;
int pulsos = 0;
int x = -1;
int y = 0;
boolean cambio = false;
boolean tiempoSuperado = true;
long tiempoAnterior = 0;
char t0[] = {'0',' '};
char t1[] = {'1'};
char t2[] = {'A','B','C','a','b','c','2'};
char t3[] = {'D','E','F','d','e','f','3'};
char t4[] = {'G','H','I','g','h','i','4'};
char t5[] = {'J','K','L','j','k','l','5'};
char t6[] = {'M','N','O','m','n','o','6'};
char t7[] = {'P','Q','R','S','p','q','r','s','7'};
char t8[] = {'T','U','V','t','u','v','8'};
char t9[] = {'W','X','Y','Z','w','x','y','z','9'};
char keys[rowsCount][columsCount] = {
{'D','#','0','*'},
{'C','9','8','7'},
{'B','6','5','4'},
{'A','3','2','1'}
};
const byte rowPins[rowsCount] = {36, 34, 32, 30};
const byte columnPins[columsCount] = {44, 42, 40, 38};
Keypad keypad = Keypad(makeKeymap(keys), rowPins, columnPins, rowsCount, columsCount);
void setup() {
Serial.begin(9600);
// assign default color value
if ( u8g.getMode() == U8G_MODE_R3G3B2 )
u8g.setColorIndex(255); // white
else if ( u8g.getMode() == U8G_MODE_GRAY2BIT )
u8g.setColorIndex(1); // max intensity
else if ( u8g.getMode() == U8G_MODE_BW )
u8g.setColorIndex(1); // pixel on
}
void loop() {
char key = keypad.getKey();
tiempoSuperado = millis() > tiempoAnterior + 1000;
if(c1=='C' and c2=='L' and c3=='C' and (tiempoSuperado)){
//u8g.clear();
x=-1;
y=0;
pulsos=0;
}
if(key){
boolean cambio = key==anterior && !tiempoSuperado;
if(tiempoSuperado){
if(key==anterior) x++;
pulsos=0;
}
if(key!=anterior){
tiempoSuperado =true;
pulsos = 0;
x++;
}
tiempoAnterior = millis();
switch (key) {
case '0':
pulsos = cambio ? (++pulsos%sizeof(t0)) : 0;
seleccionado = t0[pulsos];
break;
case '1':
pulsos = cambio? (++pulsos%sizeof(t1)) : 0;
seleccionado = t1[pulsos];
break;
case '2':
pulsos = cambio ? (++pulsos%sizeof(t2)) : 0;
seleccionado = t2[pulsos];
break;
case '3':
pulsos = cambio ? (++pulsos%sizeof(t3)) : 0;
seleccionado = t3[pulsos];
break;
case '4':
pulsos = cambio ? (++pulsos%sizeof(t4)) : 0;
seleccionado = t4[pulsos];
break;
case '5':
pulsos = cambio ? (++pulsos%sizeof(t5)) : 0;
seleccionado = t5[pulsos];
break;
case '6':
pulsos = cambio ? (++pulsos%sizeof(t6)) : 0;
seleccionado = t6[pulsos];
break;
case '7':
pulsos = cambio ? (++pulsos%sizeof(t7)) : 0;
seleccionado = t7[pulsos];
break;
case '8':
pulsos = cambio ? (++pulsos%sizeof(t8)) : 0;
seleccionado = t8[pulsos];
break;
case '9':
pulsos = cambio ? (++pulsos%sizeof(t9)) : 0;
seleccionado = t9[pulsos];
break;
default:
seleccionado = key;
}
c3 = cambio ? c3 : c2;
c2 = cambio ? c2 : c1;
c1 = cambio ? seleccionado : c1;
anterior = key;
y = x == 16 ? ++y%2 : y ;
x=x%16;
//u8g.setCursor(x,y);
u8g.print(seleccionado);
}
}