Paso 1: Subir código al arduino y listo
#include
inicializar la biblioteca con los números de los pines de la interfaz lcd LiquidCrystal (12, 11, 5, 4, 3, 2); int user_n; int num; iii int = 0;
int n = 1; int voto [6] = {0,0,0,0,0,0}; flaggg int = 0; int flagg = 5; flaggy int = 0; int flagggg = 0; int pbutton2 = 0; int m; Int nn = 0; int 9 = 9; #include int clave = 15; int clave2 = 14; int p = 0; f //for; retraso const filas bytes = 4; cuatro filas COLS byte const = 3; tres columnas char teclas [filas] [COLS] = {{'A', 'B','C '}, {tenía ', 'E', 'F'}, {'G', 'H', 'I'}, {'K', 'L', soy '}};
byte const ROWS2 = 4; byte const cuatro filas COLS2 = 3; tres columnas char keys2 [ROWS2] [COLS2] = {{' n ', 'O', 'P'}, {'Q', 'R', de '}, {' t ', 'U', 'W'}, {'* ',' > ',' <'},}; byte rowPins [filas] = {41, 43, 45, 47}; conectar a las conexiones de la fila del teclado byte colPins [COLS] = {49, 51, 53}; conectar a las conexiones de la columna del teclado
byte rowPins2 [ROWS2] = {22, 24, 26, 28}; conectar a las conexiones de la fila del teclado byte colPins2 [COLS2] = {30, 32, 34};
Teclado teclado = teclado (makeKeymap(keys), rowPins colPins, filas, COLS); //Main de función para iniciar teclado teclado keypad2 = teclado (makeKeymap(keys2), rowPins2, colPins2, ROWS2, COLS2);
void setup() {//runs solamente una vez pinMode(key,INPUT), pinMode(key2,INPUT), pinMode (nueve, salida); //set contraste de lcd analogWrite(nine,370);
Serial.Begin(9600); } char nombre [5] [20]; array //double nombre de candidtes
void enter() {clave char = keypad.getKey(); char clave2 = keypad2.getKey();
Si (clave) {Serial.println(key); p = 5;} if(key2) {Serial.println(key2); p = 5;}
} void setupdisplay() {lcd.begin (8, 2); lcd.setCursor(2,0); lcd.print ("Candidtes no"); LCD.Begin (8, 2); lcd.setCursor(5,1); LCD.Print("Added!");
Delay(1000); / / detener 1 INRO lcd.begin (8, 2); lcd.setCursor(3,0); LCD.Print ("oprima cualquier"); LCD.Begin (8, 2); lcd.setCursor(5,1); LCD.Print("Button"); Delay(1000); / / detener 1 INRO enter();
}
int numberofusers() {char keyb22 = 'a'; int n = 0; if(flaggg==0) {n = 0; flaggg = 1;} while(n!=1000) {lcd.begin (8, 2); lcd.setCursor(0,0); lcd.print ("ingresar número de"); LCD.Begin (8, 2); lcd.setCursor(0,1); LCD.Print("candidates:"); lcd.setCursor(12,1); LCD.Print(n); keyb22=keyb2(); m = n; Num = n; if(keyb22=='*') {n = 1000;} si (keyb22 =='< ' & & n! = 0) {n = n-1;} si (keyb22 =='> ' & & n! = 5) {n = n + 1;} delay(100);
}
LCD.Begin (8, 2); lcd.setCursor(0,0); LCD.Print ("tiene elegido"); LCD.Begin (8, 2); lcd.setCursor(0,1); LCD.Print(m); lcd.setCursor(4,1); LCD.Print («candidatas»); Delay(1000); pbutton2 = 9;
Return(m);
}
char keyb() {}
clave char = keypad.getKey(); Si (clave) {Serial.println(key); p = 5;} return(key);
}
char keyb2() {char clave2 = keypad2.getKey();
if(KEY2) {Serial.println(key2); p = 5;} return(key2);
}
void error() {pbutton2 = 0; lcd.begin (8, 2); lcd.setCursor(0,0); lcd.print("Error!"); / / lcd.begin (8, 2); lcd.setCursor(0,1); lcd.print("Restarting!"); delay(2000); setupdisplay();
}
void reset() {p = 0; pbutton2 = 0; setupdisplay();
}
void entername() {int n = 0, m = 0; if (user_n == 0 & & flagggg == 0) {error();} flagggg = 5;
while(user_n!=0) {char k1 = '$', k2 = '$'; lcd.setCursor(0,0); lcd.begin (8, 2), lcd.print ("entrar nombre de"); LCD.Begin (8, 2); lcd.setCursor(0,1); LCD.Print("Candidate:"); lcd.setCursor(12,1); LCD.Print(user_n); Delay(1000); mientras que (k2! ='* ') {k1 = '$'; k2 = '$'; k1=keyb(); k2=keyb2(); if(k1) {nombre [user_n] [nn] = k1; if(flagg==5) {lcd.begin (8, 2); lcd.setCursor(0,0); lcd.print("Name"); lcd.setCursor(6,0); lcd.print(user_n); flagg = 0;
} / / lcd.begin (8, 2); LCD.Print("Candidate:"); lcd.setCursor(nn,1); LCD.Print(Name[user_n][NN]); LCD.Print(K1); nn = nn + 1;
Delay(100);
} else if(k2) {nombre de if(k2!='*') [user_n] [nn] = k2;
if(Flagg==5) {lcd.begin (8, 2); lcd.setCursor(0,0); lcd.print("Name"); lcd.setCursor(6,0); lcd.print(user_n); flagg = 0;}
LCD.Begin (8, 2); LCD.Print("Candidate:"); lcd.setCursor(nn,1); LCD.Print(Name[user_n][NN]); LCD.Print('A');
nn = nn + 1; Delay(100);
Delay(1000); lcd.begin}} (8, 2); lcd.setCursor(0,0); LCD.Print ("nombre guardado!"); Delay(1000); user_n = user_n-1; Flagg = 5; NN = 0;
} //END MIENTRAS BUCLE PARA EL NÚMERO DE ENTRADA DE USUARIO
systemready();
}
void systemready()
{
if(flaggy==0) {lcd.begin (8, 2); lcd.setCursor(0,0); lcd.print ("por favor elegir"); lcd.setCursor(0,1); lcd.print ("el candidato"); delay(1000); flaggy = 5;} char k2=keyb2(); LCD.Begin (8, 2); lcd.setCursor(0,0); LCD.Print(Name[n][0]); LCD.Print(Name[n][1]); LCD.Print(Name[n][2]); LCD.Print(Name[n][3]); LCD.Print(Name[n][4]); LCD.Print(Name[n][5]); LCD.Print(Name[n][6]); LCD.Print(Name[n][7]); LCD.Print(Name[n][8]); LCD.Print(Name[n][9]); LCD.Print(Name[n][10]); LCD.Print(Name[n][11]); LCD.Print(Name[n][12]); LCD.Print(Name[n][13]); LCD.Print(Name[n][14]); LCD.Print(Name[n][15]);
LCD.Print(Name[n][16]); Delay(100); mientras (analogRead(key)!=0) {lcd.begin (8, 2); lcd.setCursor(0,0); lcd.print ("sin permiso"); lcd.setCursor(0,1); LCD.Print ("sin clave!!!!"); Delay(1000);
} if(k2) {si (k2 =='< ' & & n
LCD.Print(Name[n][16]); Delay(1000); }
} Si (k2 =='> ' & & n > 1) {n = n-1; lcd.setCursor(0,1); lcd.begin (8, 2), lcd.print ("Pulse * para elegir"); lcd.setCursor(0,0); lcd.print(name[n][0]); lcd.print(name[n][1]); lcd.print(name[n][2]); lcd.print(name[n][3]); lcd.print(name[n][4]); lcd.print(name[n][5]); lcd.print(name[n][6]); lcd.print(name[n][7]); lcd.print(name[n][8]); lcd.print(name[n][9]); lcd.print(name[n][10]); lcd.print(name[n][11]); lcd.print(name[n][12]); lcd.print(name[n][13]); lcd.print (nombre [n] [ 14]); LCD.Print(Name[n][15]); LCD.Print(Name[n][16]); Delay(1000); } Si (k2 =='* ' & & analogRead(key)==0) {voto [n] = votos + 1 [n]; lcd.begin (8, 2); lcd.setCursor(0,0); lcd.print ("¡ gracias!"); lcd.setCursor(0,1); lcd.print ("ha votado!"); delay(1000); systemready();
}
if(K2=='N') {int temp = 0; int gran; para (int i = 0; me < = 5; ++ me) {si (votos [i] > temp) {gran = i; temp = voto [i];}
} //end de para lcd.begin (8, 2); lcd.setCursor(0,0); LCD.Print ("ganador votos:"); lcd.setCursor(13,0); LCD.Print(Temp);
lcd.setCursor(0,1); LCD.Print(Name[Great][0]); LCD.Print(Name[Great][1]); LCD.Print(Name[Great][2]); LCD.Print(Name[Great][3]); LCD.Print(Name[Great][4]); LCD.Print(Name[Great][5]); LCD.Print(Name[Great][6]); LCD.Print(Name[Great][7]); LCD.Print(Name[Great][8]); LCD.Print(Name[Great][9]); LCD.Print(Name[Great][10]); LCD.Print(Name[Great][11]); LCD.Print(Name[Great][12]); LCD.Print(Name[Great][13]); LCD.Print(Name[Great][14]); LCD.Print(Name[Great][15]); LCD.Print(Name[Great][16]);
Delay(10000); RESET();
}
}
void loop() {while(pbutton==0) {while(iii==19) {nombre [1] [iii] =' '; iii = iii + 1;}
III = 0;
while(III==19) {nombre [2] [iii] =' '; iii = iii + 1;}
III = 0;
while(III==19) {nombre [3] [iii] =' '; iii = iii + 1;}
III = 0; while(III==19) {nombre [4] [iii] =' '; iii = iii + 1;} iii = 0;
while(III==19) {nombre [5] [iii] =' '; iii = iii + 1;} setupdisplay(); } while(pbutton2==0) {user_n=numberofusers();} entername(); }