Galera eu estava dando uma olhada num código que peguei no fisicarduino.com que por sinal é bem legal, ele usa um teclado Matricial 4 x 3 ou de membrana para ativar leds dependendo da senha, se correta acende verde se incorreta vermelho e para ativar o teclado pressionando # acende a laranja. Eu queria ver se tem como alterar o código para usar em um projeto, mais tenho que ver como alterar a senha via teclado. Quem pode me ajudar?

 

Olha o código:

 

#include 
int count = 0;
char pass [8] = {'1', '2', '3', '4', '5', '6', '7', '8'};
const int yellowPin = 11;
const int redPin = 12;
const int greenPin = 10;
const int audioPin = 22;
const int duration = 200;
const byte ROWS = 4; //Quatro linhas
const byte COLS = 3; //Três colunas
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'*','0','#'}
};
byte rowPins[ROWS] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {6, 7, 8}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
pinMode(audioPin, OUTPUT);
pinMode(yellowPin, OUTPUT);
pinMode(redPin, OUTPUT);
pinMode(greenPin, OUTPUT);
key_init();
}
void loop(){
char key = keypad.getKey();
if (key != NO_KEY){
if (key == '#') { 
code_entry_init();
int entrada = 0;
while (count < 8 ){
char key = keypad.getKey();
if (key != NO_KEY){
entrada += 1;
tone(audioPin, 1080, 100);
delay(duration);
noTone(audioPin);
if (key == pass[count])count += 1;
if ( count == 8 ) unlocked();
if ((key == '#') || (entrada == 8)){
key_init(); 
break;}
}
}
}
}
}

void key_init (){
count = 0;
digitalWrite(redPin, HIGH);
digitalWrite(yellowPin, LOW);
digitalWrite(greenPin, LOW);
tone(audioPin, 1080, 100);
delay(duration);
noTone(audioPin);
tone(audioPin, 980, 100);
delay(duration);
noTone(audioPin);
tone(audioPin, 770, 100);
delay(duration);
noTone(audioPin);
}

void code_entry_init(){
count = 0;
tone(audioPin, 1500, 100);
delay(duration);
noTone(audioPin);
tone(audioPin, 1500, 100);
delay(duration);
noTone(audioPin);
tone(audioPin, 1500, 100);
delay(duration);
noTone(audioPin);
digitalWrite(redPin, LOW);
digitalWrite(yellowPin, HIGH);
digitalWrite(greenPin, LOW);
}

void unlocked(){
digitalWrite(redPin, LOW);
digitalWrite(yellowPin, LOW);
while ( true ){
digitalWrite(greenPin, HIGH);
tone(audioPin, 2000, 100);
delay(duration);
noTone(audioPin);
break;

}
}

//Fim

Exibições: 1398

Responder esta

© 2024   Criado por Marcelo Rodrigues.   Ativado por

Badges  |  Relatar um incidente  |  Termos de serviço