Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <LiquidCrystal.h>
- LiquidCrystal lcd (12, 8, 0, 9, 10, 11);
- //LCD anschließen
- const int Piezo = 3;
- const int LED = 1;
- const int Bewegungsmelder = 13;
- const int E1 = 5; //Eingabe: 1
- const int E2 = A5; // Eingabe: 2
- const int E3 = 7; // Eingabe: 3
- const int E4 = 6; //Eingabe: 4
- const int Enter = 4; //Pin bestätigen
- const int Clear = 1; //Eingabe zurücksetzen
- char Pin[4] = {'1', '2', '3', '4'}; //Richtiger Pin
- char Entered[4] = {'0', '0', '0', '0'}; //eingegebener Pin
- int count;
- int right;
- void setup() {
- lcd.begin(16, 2); //LCD starten
- lcd.clear(); //LCD zurücksetzen
- pinMode(Piezo, OUTPUT);
- pinMode(LED, OUTPUT);
- pinMode(Bewegungsmelder, INPUT);
- pinMode(E1, INPUT);
- pinMode(E2, INPUT);
- pinMode(E3, INPUT);
- pinMode(E4, INPUT);
- pinMode(Enter, INPUT);
- pinMode(Clear, INPUT); //Definition der einzelnen Pins
- Serial.begin(9600); //startet Seriellen Monitor
- attachInterrupt(0, ResetPin, RISING); //Interrupt zum reseten des Codes
- }
- void ResetPin() {
- for (int i = 0; i < 5; i++) {
- Entered[i] = 0; //Resetet den eingegebenen Pin
- }
- }
- void loop() {
- digitalWrite(LED, LOW);
- delay(500);
- digitalWrite(LED, LOW);
- do {
- if (digitalRead(Clear) == HIGH) {
- break;
- }
- } while (digitalRead(Clear) == LOW); //Wenn die Cleartaste gedrückt wird, geht's weiter.
- Serial.println("Test1");
- do {
- if (digitalRead(Bewegungsmelder) == HIGH) {
- break;
- }
- } while (digitalRead(Bewegungsmelder) == LOW); //Wenn eine Bewegung erkannt wird, geht's weiter.
- Serial.println("Test2");
- lcd.setCursor(0, 0);
- lcd.print("Pin eingeben");
- delay(3000);
- lcd.clear();
- for (count = 0; count < 5; count++) {
- do {
- if ((digitalRead(E1) == HIGH) || (digitalRead(E2) == HIGH) || (digitalRead(E3) == HIGH) || (digitalRead(E4) == HIGH)) {
- goto weiter;
- }
- } while (digitalRead(Clear) == LOW); //Wenn eine Taste zur Pineingabe gedrückt wird, geht's weiter
- weiter:
- if (digitalRead(E1) == HIGH) {
- Entered[count] = 1;
- }
- else if (digitalRead(E2) == HIGH) {
- Entered[count] = 2;
- }
- else if (digitalRead(E3) == HIGH) {
- Entered[count] = 3;
- }
- else if (digitalRead(E4) == HIGH) {
- Entered[count] = 4;
- }
- lcd.setCursor(count, 0);
- lcd.print("*"); //Stern ersetzt eingegebene Nummer.
- }
- for (count = 0; count < 5; count++) {
- if (Entered[count] = Pin[count]) {
- right++;
- }
- }
- if (right = 4) {
- lcd.clear();
- lcd.print("richtiger Code");
- }
- else {
- lcd.clear();
- lcd.print("falscher Code");
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement