Oi PESSOAL Meu nome GÉRIS MARIO tô precisando de uma ajuda e acho que aqui alguem pode me ajudar.
Tenho um leitor de codigos de barras tipo esses de caixas de supermercado, quero usar pra um controle de acesso,
tenho o codigo do programa de acesso por teclado matricial e tenho o codigo do programa pra conectar o leitor no arduino mega,
todos os dois ja conseguir fazer funcionar separadamente ,queria saber se tem como eu unir os dois codigos e fazer o leitor codigo de barras funcionar no lugar do teclado matricial,
com o teclado a pessoa tem que digitar uma senha,quero com o leitor porque é so passar o cartão de codigos com a senha.
Sei que q tem como fazer com Rfid mais o cartao de codigo de barras fica mais barato se acaso a pessoa quebrar ou perder.
SE ALGUEM PUDER ME AJUDAR FICAREI FELIZ OBRIGADO.
SEGUE A BAIXO OS CODIGOS DO ACSSO POR TECLADO E O DO LEITOR
CODIGO ACESSO POR TECLADO
#include <Password.h> // Biblioteca utilizada para controle de senha.
#include <Keypad.h> // Biblioteca para controle do teclado de matrizes.
// Senha utilizada para acionamento do rele.
Password password = Password( "1234" );
const byte ROWS = 4; // Quatro linhas por...
const byte COLS = 4; // Quatro colunas.
// Define o Keypad (mapa do circuito do teclado).
char keys[ROWS][COLS] = {
{'7','8','9','A' },
{'4','5','6','B' },
{'1','2','3','C' },
{'*','0','#','D' }
};
byte rowPins[ROWS] = { 8, 7, 6, 9 }; // PINOS DE CONEXAO DAS LINHAS DO TECLADO
byte colPins[COLS] = { 5, 4, 3, 2 }; //PINOS DE CONEXAO DAS COLUNAS DO TECLADO
Keypad keypad=Keypad(makeKeymap(keys), rowPins, colPins, ROWS, COLS);
void setup(){
pinMode(11, OUTPUT); // Define pino 11 como saÃda.
Serial.begin(9600); // Inicializa Serial Monitor.
keypad.addEventListener(keypadEvent);
keypad.setDebounceTime(250);
}
void loop(){
keypad.getKey();
}
void keypadEvent(KeypadEvent eKey){
switch (keypad.getState()){ // Condição switch...
case PRESSED: // Se precionado algum botão...
Serial.print("Digitado: "); // Aparecera no Serial Monitor, Digitado: "X".
Serial.println(eKey); // Armazena numero digitado na variável eKey.
switch (eKey){
// Pressionando "0" confirma se a senha foi digitado corretamente.
case '0':
guessPassword();
break;
default:
password.append(eKey);
}
}
}
void guessPassword(){
// Informa no Serial Monitor "Verificando, aguarde...".
Serial.print("Verificando, aguarde... ");
if (password.evaluate()){
// Informa no Serial Monitor "Acionando rele...".
Serial.println("Acionando rele 11... ");
digitalWrite(11, HIGH); // Ativa o rele.
delay(2000); // Rele fica acionado por 2 segundos e depois...
digitalWrite(11, LOW); // Desativa o rele.
password.reset(); // Apaga a senha.
}
// ============================================================================
else{
digitalWrite(4, LOW);
Serial.println("Senha Invalida !");
password.reset(); // Apaga a senha.
}
}
================================================================
CODIGO DO LEITOR
#include <hid.h> //Add to Oleg Mazurov code to Bar Code Scanner
#include <hiduniversal.h> //Add to Oleg Mazurov code to Bar Code Scanner
#include <usbhub.h>
#include <LiquidCrystal.h>
#include <avr/pgmspace.h>
#include <Usb.h>
#include <usbhub.h>
#include <avr/pgmspace.h>
#include <hidboot.h>
#define DISPLAY_WIDTH 16
//initialize the LCD library with the numbers of the interface pins//
LiquidCrystal lcd(7, 6, 5, 4, 3, 2);
USB Usb;
USBHub Hub(&Usb); //I enable this line
HIDUniversal Hid(&Usb); //Add this line so that the barcode scanner will be recognized, I use "Hid" below
HIDBoot<HID_PROTOCOL_KEYBOARD> Keyboard(&Usb);
class KbdRptParser : public KeyboardReportParser
{
void PrintKey(uint8_t mod, uint8_t key); // Add this line to print character in ASCII
protected:
virtual void OnKeyDown (uint8_t mod, uint8_t key);
virtual void OnKeyPressed(uint8_t key);
};
void KbdRptParser::OnKeyDown(uint8_t mod, uint8_t key)
{
uint8_t c = OemToAscii(mod, key);
if (c)
OnKeyPressed(c);
}
/* what to do when symbol arrives */
void KbdRptParser::OnKeyPressed(uint8_t key)
{
static uint32_t next_time = 0; //watchdog
static uint8_t current_cursor = 0; //tracks current cursor position
if( millis() > next_time ) {
lcd.clear();
current_cursor = 0;
delay( 5 ); //LCD-specific
lcd.setCursor( 0,0 );
}//if( millis() > next_time ...
next_time = millis() + 200; //reset watchdog
if( current_cursor++ == ( DISPLAY_WIDTH + 1 )) { //switch to second line if cursor outside the screen
lcd.setCursor( 0,1 );
}
Serial.print( (char)key ); //Add char to print correct number in ASCII
lcd.print( (char)key ); //Add char to print correct number in ASCII
};
KbdRptParser Prs;
void setup()
{
Serial.begin( 115200 );
Serial.println("TUDO PRONTO");
if (Usb.Init() == -1) {
Serial.println("OSC did not start.");
}
delay( 200 );
Hid.SetReportParser(0, (HIDReportParser*)&Prs); //Here I change "Keyboard" for "Hid"
// set up the LCD's number of columns and rows:
lcd.begin(DISPLAY_WIDTH, 2);
lcd.clear();
lcd.noAutoscroll();
lcd.print("Ready");
delay( 200 );
}
void loop()
{
Usb.Task();
}
Moderator: Please use tags to post codes