Bonjour,
Ayant commencé à bidouiller sur un arduino depuis 6 mois, je me suis lancé dans le projet de faire une bombe d'airsoft ( Qui serait équipé d'un arduino UNO, Keypad, d'un écran LCD avec module I2C ainsi que des LEDS et d'un buzzer).
Actuellement je suis à la partie ou je cherche à mettre un son via un buzzer dès que n'importe quel touche de mon keypad est pressé. Mais j'ai beau cherché depuis un moment impossible de trouver....
Je vous remercie d'avance de l'aide que vous pourriez m'apporter.
#include <Keypad.h>
#include <TM1637Display.h>
#include <Wire.h>
const int ROW_NUM = 4; //four rows
const int COLUMN_NUM = 4; //three columns
char keys[ROW_NUM][COLUMN_NUM] = {
{'1','2','3','A'},
{'4','5','6','B'},
{'7','8','9','C'},
{'*','0','#','D'}
};
byte pin_rows[ROW_NUM] = {5, 4, 3, 2}; //connect to the row pinouts of the keypad
byte pin_column[COLUMN_NUM] = {9, 8, 7, 6}; //connect to the column pinouts of the keypad
//byte pin_rows[ROW_NUM] = {9, 8, 7, 6}; //connect to the row pinouts of the keypad
//byte pin_column[COLUMN_NUM] = {5, 4, 3, 2}; //connect to the column pinouts of the keypad
Keypad keypad = Keypad( makeKeymap(keys), pin_rows, pin_column, ROW_NUM, COLUMN_NUM );
int keyNum = 0;
const String password = "5445"; // change your password here
String input_password;
const int CLK = 12; //Set the CLK pin connection to the display Emplacement du LCD
const int DIO = 13; //Set the DIO pin connection to the display Emplacement du LCD
const int SPEAKER = 10; // Emplacement du Buzzer
TM1637Display display(CLK, DIO); //set up the 4-Digit Display.
void setup()
{
pinMode(SPEAKER, OUTPUT); // Buzzer - PIN 10
Serial.begin(9600);
input_password.reserve(32); // maximum input characters is 33, change if needed
for(int i = 0; i< 3; i++)
display.setBrightness(5); //set the diplay to maximum brightness
}
void loop(){
char key = keypad.getKey();
if(key){
Serial.println(key);
if(key=='*'){
keyNum = 0;
input_password = ""; // clear input password
} else if(key == '#') {
if(password == input_password) {
Serial.println("Acces Autorise!");
tone(10,1300);
delay(300);
noTone(10);
delay(500);
// DO YOUR WORK HERE
} else {
Serial.println("Acces Refuse!");
keyNum = 0;
}
input_password = ""; // clear input password
} else {
input_password += key; // append new character to input password string
{
keyNum = (keyNum*10) + (int(key)-48);
}
}
}
display.showNumberDec(keyNum);
}