ah d’accord
#include <Wire.h>
#include <DS3231.h>
#include <LiquidCrystal.h>
#include <Keypad.h>
DS3231 clock;
RTCDateTime dt;
int tempPin = 0;
// BS E D4 D5 D6 D7
LiquidCrystal lcd(7, 8, 9, 10, 11, 12);
//the time we give the sensor to calibrate (10-60 secs according to the datasheet)
int calibrationTime = 30;
//the time when the sensor outputs a low impulse
long unsigned int lowIn;
//the amount of milliseconds the sensor has to be low
//before we assume all motion has stopped
int pirPin = 3; //the digital pin connected to the PIR sensor's output
const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
//define the cymbols on the buttons of the keypads
char hexaKeys[ROWS][COLS] = {
{'1','2','3'}
};
byte rowPins[ROWS] = {13}; //connect to the row pinouts of the keypad
byte colPins[COLS] = {5, 4, 2 }; //connect to the column pinouts of the keypad
char* ourCode = "321";
int currentPosition = 0;
//initialize an instance of class NewKeypad
Keypad customKeypad = Keypad( makeKeymap(hexaKeys), rowPins, colPins, ROWS, COLS);
//variables globales
void(* reboot) (void) = 0;
int tonePin = 6;
void setup()
{
lcd.begin(16, 2);
clock.begin();
// Send sketch compiling time to Arduino
clock.setDateTime(__DATE__, __TIME__);
heure();
delay(2000);
lcd.clear();
comptearebours();
lcd.clear();
Serial.begin(9600);
pinMode(pirPin, INPUT);
digitalWrite(pirPin, LOW);
//give the sensor some time to calibrate
Serial.print("calibrating3 sensor ");
for(int i = 0; i < calibrationTime; i++){
Serial.print(".");
}
Serial.println(" done");
Serial.println("SENSOR ACTIVE");
Serial.println("Initialize DS1307");
}
void loop()
{
heure();
if(digitalRead(pirPin) == HIGH){
temperature();
lcd.clear();}
if(digitalRead(pirPin) == LOW){
clavier();
}
}
void temperature()
{
int tempReading = analogRead(tempPin);
// This is OK
double tempK = log(10000.0 * ((1024.0 / tempReading - 1)));
tempK = 1 / (0.001129148 + (0.000234125 + (0.0000000876741 * tempK * tempK )) * tempK ); // Temp Kelvin
float tempC = tempK - 273.15; // Convert Kelvin to Celcius
float tempF = (tempC * 9.0)/ 5.0 + 32.0; // Convert Celcius to Fahrenheit
// Display Temperature in C
lcd.setCursor(0, 1);
lcd.print("Temp C ");
lcd.setCursor(6, 1);
// Display Temperature in C
lcd.print(tempC);
delay(500);
}
void heure()
{
dt = clock.getDateTime();
// set the cursor to column 0, line 1
// (note: line 1 is the second row, since counting begins with 0):
// print the number of seconds since reset:
//lcd.print(millis()/1000);
lcd.setCursor(0, 0);
lcd.print(dt.hour); lcd.print(":");
lcd.print(dt.minute); lcd.print(":");
lcd.print(dt.second);
}
void comptearebours()
{
for (byte digit = 12; digit > 0; --digit)
{
delay(1000);
lcd.setCursor(0,2);
lcd.print(digit-2);
if (digit == 1)
{
// lancer la musique
lcd.clear();
lcd.print("Musique!!");
midi();
}
}
}
void clavier()
{
char key = customKeypad.getKey();
Serial.print(key);
if (int(key) != 0) {
if (key == ourCode[currentPosition])
{
++currentPosition;
if (currentPosition == 3)
{
unlockDoor();
currentPosition = 0;
}
} else {
invalidCode();
currentPosition = 0;
}
}
}
void invalidCode()
{
lcd.clear();
lcd.setCursor(0,1);
lcd.print("CODE REFUSE");
delay(5000);
}
void unlockDoor()
{
lcd.clear();
lcd.setCursor(0,1);
lcd.print("CODE BON");
delay(5000);
heure();
delay(5000);
reboot();
}
void midi() {
tone(tonePin, 523, 877.1925);
delay(974.658333333);
tone(tonePin, 587, 219.298125);
delay(243.664583333);
tone(tonePin, 391, 219.298125);
delay(243.664583333);
tone(tonePin, 523, 219.298125);
delay(243.664583333);
tone(tonePin, 659, 219.298125);
delay(243.664583333);
tone(tonePin, 391, 219.298125);
delay(243.664583333);
tone(tonePin, 523, 877.1925);
delay(974.658333333);
tone(tonePin, 587, 219.298125);
delay(243.664583333);
tone(tonePin, 391, 219.298125);
delay(243.664583333);
tone(tonePin, 523, 219.298125);
delay(243.664583333);
tone(tonePin, 659, 219.298125);
delay(243.664583333);
tone(tonePin, 391, 219.298125);
delay(243.664583333);
tone(tonePin, 523, 877.1925);
delay(974.658333333);
tone(tonePin, 659, 219.298125);
delay(243.664583333);
tone(tonePin, 880, 219.298125);
delay(243.664583333);
tone(tonePin, 783, 219.298125);
delay(243.664583333);
tone(tonePin, 391, 219.298125);
delay(243.664583333);
tone(tonePin, 659, 219.298125);
delay(243.664583333);
tone(tonePin, 587, 1754.385);
delay(1949.31666667);
delay(243.664583333);
tone(tonePin, 523, 877.1925);
delay(974.658333333);
tone(tonePin, 587, 219.298125);
delay(243.664583333);
tone(tonePin, 391, 219.298125);
delay(243.664583333);
tone(tonePin, 523, 219.298125);
delay(243.664583333);
tone(tonePin, 659, 219.298125);
delay(243.664583333);
tone(tonePin, 391, 219.298125);
delay(243.664583333);
tone(tonePin, 523, 877.1925);
delay(974.658333333);
tone(tonePin, 587, 219.298125);
delay(243.664583333);
tone(tonePin, 391, 219.298125);
delay(243.664583333);
tone(tonePin, 523, 219.298125);
delay(243.664583333);
tone(tonePin, 659, 219.298125);
delay(243.664583333);
tone(tonePin, 391, 219.298125);
delay(243.664583333);
tone(tonePin, 523, 877.1925);
delay(974.658333333);
tone(tonePin, 659, 219.298125);
delay(243.664583333);
tone(tonePin, 880, 219.298125);
delay(243.664583333);
tone(tonePin, 783, 219.298125);
delay(243.664583333);
tone(tonePin, 391, 219.298125);
delay(243.664583333);
tone(tonePin, 659, 219.298125);
delay(243.664583333);
tone(tonePin, 587, 1754.385);
delay(1949.31666667);
delay(243.664583333);
tone(tonePin, 587, 877.1925);
delay(974.658333333);
tone(tonePin, 659, 219.298125);
delay(243.664583333);
tone(tonePin, 440, 219.298125);
delay(243.664583333);
tone(tonePin, 587, 219.298125);
delay(243.664583333);
tone(tonePin, 659, 219.298125);
delay(243.664583333);
tone(tonePin, 440, 219.298125);
delay(243.664583333);
tone(tonePin, 587, 877.1925);
delay(974.658333333);
tone(tonePin, 659, 219.298125);
delay(243.664583333);
tone(tonePin, 440, 219.298125);
delay(243.664583333);
tone(tonePin, 587, 219.298125);
delay(243.664583333);
tone(tonePin, 659, 219.298125);
delay(243.664583333);
tone(tonePin, 391, 219.298125);
delay(243.664583333);
tone(tonePin, 523, 877.1925);
delay(974.658333333);
tone(tonePin, 587, 219.298125);
delay(243.664583333);
tone(tonePin, 659, 219.298125);
delay(243.664583333);
tone(tonePin, 739, 219.298125);
delay(243.664583333);
tone(tonePin, 783, 219.298125);
delay(243.664583333);
tone(tonePin, 880, 219.298125);
delay(243.664583333);
tone(tonePin, 783, 1754.385);
delay(1949.31666667);
delay(243.664583333);
tone(tonePin, 587, 877.1925);
delay(974.658333333);
tone(tonePin, 659, 219.298125);
delay(243.664583333);
tone(tonePin, 440, 219.298125);
delay(243.664583333);
tone(tonePin, 587, 219.298125);
delay(243.664583333);
tone(tonePin, 659, 219.298125);
delay(243.664583333);
tone(tonePin, 440, 219.298125);
delay(243.664583333);
tone(tonePin, 587, 877.1925);
delay(974.658333333);
tone(tonePin, 659, 219.298125);
delay(243.664583333);
tone(tonePin, 440, 219.298125);
delay(243.664583333);
tone(tonePin, 587, 219.298125);
delay(243.664583333);
tone(tonePin, 659, 219.298125);
delay(243.664583333);
tone(tonePin, 391, 219.298125);
delay(243.664583333);
tone(tonePin, 523, 877.1925);
delay(974.658333333);
tone(tonePin, 587, 219.298125);
delay(243.664583333);
tone(tonePin, 659, 219.298125);
delay(243.664583333);
tone(tonePin, 739, 219.298125);
delay(243.664583333);
tone(tonePin, 783, 219.298125);
delay(243.664583333);
tone(tonePin, 880, 219.298125);
delay(243.664583333);
tone(tonePin, 783, 1754.385);
delay(1949.31666667);
}