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
|
//Arduino
// PIN switch with 16-digit numeric keypad
// <a href="http://tronixstuff.com/tutorials" target="_blank">http://tronixstuff.com/tutorials</a> > chapter 42
#include "Keypad.h"
//#include <Wire.h>
//#include <TWILiquidCrystal.h>
//LiquidCrystal lcd(12, 11, 5, 4, 3, 2);
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keys[ROWS][COLS] =
{
{
'1','2','3','A' }
,
{
'4','5','6','B' }
,
{
'7','8','9','C' }
,
{
'*','0','#','D' }
};
byte rowPins[ROWS] = {
2, 3, 4, 5}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {
6, 7, 8, 9}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
char PIN[6]={
'0','0','0','0','0','0'}; //initialisation du code
char attempt[6]={
'0','0','0','0','0','0'}; // used for comparison
int z=0;
int x=0;
void setup()
{
pinMode(11,OUTPUT);
Serial.begin(9600);
// lcd.begin(16, 2);
Serial.println("ENTRER CODE 1 ");
}
void code()
{
int i=0;
for (int i=0; i<6; i++)
{
char key = keypad.getKey();
if (key != NO_KEY)
{
PIN[z]=key;
z++;
if (z==6)
{
Serial.println("code1 ok");
code2();
}
}
}
}
void code2()
{
Serial.println("code2 ");
int j=0;
int x=0;
for (int j=0; j<6; j++)
{
char key = keypad.getKey();
if (key != NO_KEY)
{
attempt[x]=key;
x++;
Serial.println(x);
if (x==6)
{
Serial.println("code2 ok");
}
}
}
}
void loop()
{
code();
} |
Partager