Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- Aluno: Wesley Alves Santana
- Turma: 3IELN2017
- Simulação: https://circuits.io/circuits/4014551-sistemas-programaveis-keypad-diplsay-de-7-segmentos/
- */
- // Keypad:
- const byte ROW[] = {A0, A1, A2, A3};
- // Display 7 segmentos:
- const byte COL[] = {2, 3, 4, 5};
- // Segmentos: a, b, c, d, e, f, g, p
- const byte SEG[] = {12, 13, 7, 8, 9, 11, 10, 6};
- // Teclado:
- const char KEYS[4][4] = {{'A', 'B', 'C', 'D'}, {'3', '6', '9', '#'}, {'2', '5', '8', '0'}, {'1', '4', '7', '*'}};
- //Senha Padrão:
- const char PASSWORD[] = {'B', 'C', 'D', '8', '4', '2'};
- void setup() {
- for (byte i = 2; i <= 13; i++) {
- pinMode (i, OUTPUT);
- digitalWrite (i, LOW);
- }
- Serial.begin(9600);
- Serial.println("=========================");
- }
- void loop() {
- delay(10);
- char pressedKey = getKey();
- if (pressedKey != 'w') {
- senha(pressedKey);
- }
- }
- char scanKey() {
- char r = 'w';
- for (byte i = 0; i < 4; i++) {
- digitalWrite(COL[i], HIGH);
- for (byte j = 0; j < 4; j++) {
- if (digitalRead(ROW[j])) {
- r = KEYS[i][j];
- }
- }
- digitalWrite(COL[i], LOW);
- }
- return r;
- }
- char getKey() {
- static byte estado = 0;
- char key = 'w';
- char scan = scanKey();
- switch (estado) {
- case 0:
- if (scan != 'w') {
- estado = 1;
- key = scan;
- }
- break;
- case 1:
- if (scan == 'w') {
- key = 'w';
- estado = 0;
- }
- break;
- }
- return key;
- }
- void senha(char pressedKey) {
- static bool keepTesting = true, checkPass = false;
- static byte counter = 0;
- if (pressedKey != '#') {
- Serial.print(pressedKey);
- if (keepTesting) {
- if (counter <= 5 && pressedKey == PASSWORD[counter]) {
- checkPass = true;
- counter++;
- } else {
- checkPass = false;
- keepTesting = false;
- }
- }
- } else if (checkPass) {
- counter = 0;
- keepTesting = true;
- Serial.println("\nSenha correta.");
- } else {
- counter = 0;
- keepTesting = true;
- Serial.println("\nSenha errada.");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment