bonjour a tous,
donc, j’ai un petit soucis avec un clavier 4x3 que j’essaie de faire marcher.
il ressemble en tout point a ça, mais avec 9 pin:
je n’ai aucune référence du clavier, pas même son nom, il a 9 pin, et après avoir fais des test au multimètre, j’ai:
1 2 3| 7
4 5 6| 5
7 8 9| 3
#0 *| 1
2 4 9
8
donc, mon problème est que, toutes les touches marchent, sauf le 1 et le 4, alors qu’au multimètre, ils correspondent bien.
voici le code dans lequel je l’utilise:
#include <Wire.h>
#include <LCD.h>
#include <LiquidCrystal_I2C.h>
#include <Arduino.h>
#include <TM1637Display.h>
#include <Keypad.h>
#define I2C_ADDR 0x3F
#define BACKLIGHT_PIN 3
#define En_pin 2
#define Rw_pin 1
#define Rs_pin 0
#define D4_pin 4
#define D5_pin 5
#define D6_pin 6
#define D7_pin 7
#define CLK 10
#define DIO 11
const long interval = 1000;
unsigned long currentMillis = millis();
int buzzer = 12;
const byte ROWS = 4;
const byte COLS = 3;
char keys[ROWS][COLS] = {
{'1','2','3'},
{'4','5','6'},
{'7','8','9'},
{'#','0','*'}
};
byte rowPins[ROWS] = { 9, 8, 7, 6 };
byte colPins[COLS] = { 2, 3, 4 };
Keypad keypad = Keypad( makeKeymap(keys), rowPins,
colPins, ROWS, COLS );
int n = 1;
TM1637Display display(CLK, DIO);
LiquidCrystal_I2C lcd(I2C_ADDR, En_pin, Rw_pin, Rs_pin, D4_pin, D5_pin, D6_pin, D7_pin);
void setup() {
lcd.begin (16, 2);
lcd.setBacklightPin(BACKLIGHT_PIN, POSITIVE);
lcd.setBacklight(HIGH);
lcd.home ();
pinMode(12, OUTPUT);
Serial.begin(9600);
randomSeed(analogRead(0));
}
int car(int i, uint8_t data[4], const long interval, unsigned long currentMillis, int boucle)
{
currentMillis = millis();
static unsigned long previousMillis = 0;
if (currentMillis - previousMillis >= interval && i >= 0)
{
previousMillis = currentMillis ;
int minutes = i / 60;
int secondes = i % 60;
int dizm = minutes / 10;
int unim = minutes % 10;
int dizs = secondes / 10;
int unis = secondes % 10;
data[0] = display.encodeDigit(dizm);
data[1] = display.encodeDigit(unim);
data[2] = display.encodeDigit(dizs);
data[3] = display.encodeDigit(unis);
display.setSegments(data);
i--;
}
return (i);
}
void loop()
{
int ug = 0;
int dg = 0;
int cg = 0;
int mg = 0;
int boucle = 1;
unsigned int good = 0;
uint8_t data[] = { 0xff, 0xff, 0xff, 0xff };
display.setBrightness(0x0f);
display.setSegments(data);
int i = 3000;
int code = random (1000, 10000);
int desactive = 0;
int uc = code % 10;
int dc = code / 10 % 10;
int cc = code / 100 % 10;
int mc = code / 1000 % 10;
char key = keypad.getKey();
lcd.setCursor (0, 0);
lcd.print("appuyer *");
while (key == NO_KEY)
{
key = keypad.getKey();
if (key == '*')
{
lcd.clear();
lcd.setCursor (6, 0);
lcd.print(code);
delay(20000);
lcd.clear();
}
else
{
key = NO_KEY;
Serial.println(key);
}
}
lcd.setCursor (0, 0);
lcd.print ("Choose time:");
lcd.setCursor (0, 1);
lcd.print ("1=5min-->9=45min");
key = keypad.getKey();
while (key == NO_KEY)
{
key = keypad.getKey();
if (key == '1')
{
i = 300;
}
else if (key == '2')
{
i = 600;
}
else if (key == '3')
{
i = 900;
}
else if (key == '4')
{
i = 1200;
}
else if (key == '5')
{
i = 1500;
}
else if (key == '6')
{
i = 1800;
}
else if (key == '7')
{
i = 2100;
}
else if (key == '8')
{
i = 2400;
}
else if (key == '9')
{
i = 2700;
}
else
{
key = NO_KEY;
}
}
lcd.clear();
lcd.setCursor (0,0);
lcd.print("début dans");
lcd.setCursor (0,1);
lcd.print (" 30 secondes");
delay(30000);
lcd.clear();
while ( boucle == 1 && i >= 0)
{
i = car (i, data, interval, currentMillis, boucle);
lcd.clear();
lcd.setCursor (0, 0);
lcd.print("enter code");
key = keypad.getKey();
while (key == NO_KEY && i >= 0)
{
i = car (i, data, interval, currentMillis, boucle);
key = keypad.getKey();
if (key != NO_KEY)
{
lcd.clear();
lcd.setCursor (6, 0);
lcd.print(key);
mg = key;
}
else
{
key = NO_KEY;
}
i = car (i, data, interval, currentMillis, boucle);
}
key = keypad.getKey();
while (key == NO_KEY && i >= 0)
{
i = car (i, data, interval, currentMillis, boucle);
key = keypad.getKey();
if (key != NO_KEY)
{
lcd.setCursor (7, 0);
lcd.print(key);
cg = key;
}
else
{
key = NO_KEY;
}
i = car (i, data, interval, currentMillis, boucle);
}
key = keypad.getKey();
while (key == NO_KEY&&i>=0)
{
i = car (i, data, interval, currentMillis, boucle);
key = keypad.getKey();
if (key != NO_KEY)
{
lcd.setCursor (8, 0);
lcd.print(key);
dg = key;
}
else
{
key = NO_KEY;
}
i = car (i, data, interval, currentMillis, boucle);
}
key = keypad.getKey();
while (key == NO_KEY && i >= 0)
{
i = car (i, data, interval, currentMillis, boucle);
key = keypad.getKey();
if (key != NO_KEY)
{
lcd.setCursor (9, 0);
lcd.print(key);
ug = key;
}
else
{
key = NO_KEY;
}
i = car (i, data, interval, currentMillis, boucle);
}
mg = mg - 48;
cg = cg - 48;
dg = dg - 48;
ug = ug - 48;
good = (mg * 1000) + (cg * 100) + (dg * 10) + ug;
if (good == code)
{
boucle = 2;
}
if (good != code&&good<=10000)
{
lcd.clear ();
lcd.setCursor (5, 0);
lcd.print ("error");
}
else
{
}
}
if (good == code)
{
lcd.clear ();
lcd.setCursor (4, 0);
lcd.print ("bombe");
lcd.setCursor (3,1);
lcd.print ("désamorcée");
delay (120000);
}
else
{
int buzz = 300;
delay (1000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print("****EXPLOSION***");
while (buzz>=0)
{
digitalWrite(buzzer, HIGH);
delay(1000);
digitalWrite(buzzer, LOW);
delay(1000);
buzz--;
}
delay(120000);
}
}
niveau branchement, j’ai donc mis les pin:
7 sur sortie 9
5 " " 8
3 " " 7
1 " " 6
2 " " 2
4 " " 3
9 " " 4
ais-je fais un mauvis branchement? une mauvaise déclaration?
ce qui me bloque, c’est le fait que le 7 et le # marchent, alors que ça marche par colone/ligne
merci d’avance!