Deze code wil ik invoegen in mijn alarm instalatie

Arduino specifieke Software
Berichten: 49
Geregistreerd: 09 Jun 2017, 01:59

Deze code wil ik invoegen in mijn alarm instalatie

Berichtdoor Dino » 06 Jan 2018, 13:28

Heb deze sirene gevonden en wil deze in mijn script voor de alarminstallatie voegen maar krijg deze melding, wat te doen.

Code: Alles selecteren
const int pitchLow = 200;
const int pitchHigh = 1000;
int pitchStep = 10;
int currentPitch;
int delayTime;
const int speakerPin = 8;

void setup() {
currentPitch = pitchLow;
delayTime = 10;
}
void loop(){
Sound();
}


void Sound() {
tone(speakerPin, currentPitch, 10);
currentPitch += pitchStep;
if(currentPitch >= pitchHigh) {
pitchStep = -pitchStep;
}
else if(currentPitch <= pitchLow) {
pitchStep = -pitchStep;
}
delay(delayTime);
}


Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':

(.text+0x0): multiple definition of `__vector_7'

libraries\NewPing\NewPing.cpp.o (symbol from plugin):(.text+0x0): first defined here

deze werkt wel als die dus niet wordt geïmporteerd

code zoals ik hem er nu in heb gezet .
Code: Alles selecteren
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad_I2C.h>
#include <Keypad.h>
#include <NewPing.h>
#include "NewTone.h"

const int pitchLow = 200;
const int pitchHigh = 1000;
int pitchStep = 10;
int currentPitch;
int delayTime;


const byte numRows = 4;
const byte numCols = 4;
char keypressed;
char keymap[numRows][numCols] =
{
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
int adress = 0x38;
byte rowPins[numRows] = {0, 1, 2, 3};
byte colPins[numCols] = {4, 5, 6, 7};

Keypad_I2C myKeypad = Keypad_I2C(makeKeymap(keymap), rowPins, colPins, numRows, numCols, adress);

const int buzzer = A1;
const int Slaapkamer = 2;
const int Woonkamer = 3;
const int Keuken = 4;
//const int Led = 5;//reserver
const int RedLed = 6;
const int BleuLed = 7;
const int GreenLed = 8;
const int speakerPin = 9;
const int Relay = 12;

LiquidCrystal_I2C lcd(0x27, 16, 2);
NewPing sonar(A0, A0, 2000);
String password = "1958";
String tempPassword = "";
int doublecheck;
boolean armed = false;
boolean input_pass;
boolean storedPassword = true;
boolean changedPassword = false;
boolean checkPassword = false;
int distance;
int i = 1;


void setup() {
  lcd.begin();
  lcd.backlight();
  myKeypad.begin();
  pinMode(Woonkamer, INPUT);
  pinMode(Slaapkamer, INPUT);
  pinMode(Keuken , INPUT);
  pinMode(Relay, OUTPUT);
  pinMode(RedLed , OUTPUT);
  pinMode(GreenLed , OUTPUT);
  pinMode(BleuLed , OUTPUT);
  currentPitch = pitchLow;
  delayTime = 10;

}

void loop() {
  digitalWrite(GreenLed, HIGH);
  if (armed) {
    digitalWrite(RedLed, HIGH);
    systemIsArmed();
  }
  else if (!armed) {
    digitalWrite(RedLed, LOW);
    systemIsUnarmed();
  }
}

void systemIsUnarmed() {
  int screenMsg = 0;
  lcd.clear();
  unsigned long previousMillis = 0;
  const long interval = 5000;

  while (!armed) {
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis;
      if (screenMsg == 0) {
        lcd.setCursor(0, 0);
        lcd.print("SYSTEM ALARM OFF");
        lcd.setCursor(0, 1);
        lcd.print("----------------");
        digitalWrite(Relay, LOW);
        screenMsg = 1;
      }
      else {
        lcd.setCursor(0, 0);
        lcd.print("A to arm        ");
        lcd.setCursor(0, 1);
        lcd.print("B to change pass");
        screenMsg = 0;
      }
    }
    keypressed = myKeypad.getKey();
    if (keypressed == 'A') {
      NewTone(buzzer, 500, 200);
      systemIsArmed();
    }
    else if (keypressed == 'B') {
      doublecheck = 0;
      NewTone(buzzer, 500, 200);
      digitalWrite(BleuLed, HIGH);
      storedPassword = false;
      if (!changedPassword) {
        changePassword();
        digitalWrite(BleuLed , LOW);
      }
    }
  }
}

//While system is armed
void systemIsArmed() {
  lcd.clear();
  int count = 10;
  unsigned long previousMillis = 0;
  const long interval = 1000;
  while (!armed) {
    distance = sonar.ping_cm();

    lcd.setCursor(0, 0);
    lcd.print(" SYSTEM WILL BE ");
    lcd.setCursor(0, 1);
    lcd.print("   ARMED IN ");
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis;

      if (count > 1) {
        count--;
      }
      else {
        armed = true;
        break;
      }
    }
    lcd.setCursor(12, 1);
    lcd.print(count);
  }
  while (armed) {
    lcd.setCursor(0, 0);
    lcd.print("SYSTEM IS ARMED!");
    lcd.setCursor(0, 1);
    lcd.print("----------------");
    int Kamer = digitalRead(Woonkamer);
    int SLKamer = digitalRead(Slaapkamer);
    int keuken = digitalRead(Keuken);
    int curr_distanse = sonar.ping_cm();

    if (SLKamer == HIGH) {
      lcd.clear();
      lcd.print("Slaapkamer");
      delay(1000);
      alarmFunction();
    }
    if (Kamer == HIGH) {
      lcd.clear();
      lcd.print("Kamer");
      alarmFunction();
      // unlockPassword();

    }
    if (keuken == HIGH) {
      lcd.clear();
      lcd.print("Keuken");
      delay(1000);
      alarmFunction();

    }
    if (curr_distanse < (distance - 5)) {
      alarmFunction();
      //unlockPassword();
    }
  }
}

void unlockPassword() {
  int count = 21;
retry:
  tempPassword = "";
  lcd.clear();
  i = 6;
  unsigned long previousMillis = 0;
  const long interval = 1000;
  boolean buzzerState = false;
  while (!checkPassword) {
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis;
      if (!buzzerState) {
        NewTone(buzzer, 700);
        buzzerState = true;
      }
      else {
        noNewTone(buzzer);
        buzzerState = false;
      }
      if (count > 0) {
        count--;
      }
      else {
        alarmFunction();
        break;
      }
    }
    keypressed = myKeypad.getKey();
    lcd.setCursor(0, 0);
    lcd.print("ALARM IN: ");
    if (count >= 10) {
      lcd.setCursor(14, 0);
      lcd.print(count);
    }
    else {
      lcd.setCursor(14, 0);
      lcd.print(" ");
      lcd.print(count);
    }
    lcd.setCursor(0, 1);
    lcd.print("PASS>");


    if (keypressed != NO_KEY) {
      if (keypressed == '0' || keypressed == '1' || keypressed == '2' || keypressed == '3' ||
          keypressed == '4' || keypressed == '5' || keypressed == '6' || keypressed == '7' ||
          keypressed == '8' || keypressed == '9' ) {
        tempPassword += keypressed;
        lcd.setCursor(i, 1);
        lcd.print("*");
        i++;
        NewTone(buzzer, 500, 200);
      }
      else if (keypressed == '*') {
        if (password == tempPassword) {
          armed = false;
          NewTone(buzzer, 700, 500);
          break;
        }
        else {
          tempPassword = "";
          NewTone(buzzer, 200, 200);
          delay(300);
          NewTone(buzzer, 200, 200);
          delay(300);
          goto retry;
        }
      }
    }
  }

}

//Alarm
void alarmFunction() {
  for (int i = 0; i < 10; i++) {
    digitalWrite(Relay, HIGH);
    delay(1000);
    digitalWrite(Relay, LOW);
    delay(1000);
  }
retry:
  tempPassword = "";
  lcd.clear();
  i = 6;
  unsigned long previousMillis = 0;
  const long interval = 500;
  boolean buzzerState = false;
  while (!checkPassword) {
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis;
      if (!buzzerState) {
        NewTone(buzzer, 700);
        buzzerState = true;
      }
      else {
        noNewTone(buzzer);
        buzzerState = false;
      }
    }
    keypressed = myKeypad.getKey();
    lcd.setCursor(0, 0);
    lcd.print("  !!! ALARM !!! ");
    lcd.setCursor(0, 1);
    lcd.print("PASS>");
    if (keypressed != NO_KEY) {     //Accept only numbers and *
      if (keypressed == '0' || keypressed == '1' || keypressed == '2' || keypressed == '3' ||
          keypressed == '4' || keypressed == '5' || keypressed == '6' || keypressed == '7' ||
          keypressed == '8' || keypressed == '9' ) {
        tempPassword += keypressed;
        lcd.setCursor(i, 1);
        lcd.print("*");
        i++;
      }
      else if (keypressed == '*') {
        if (password == tempPassword) {
          armed = false;
          NewTone(buzzer, 700, 500);
          break;
        }
        else {
          tempPassword = "";
          NewTone(buzzer, 200, 200);
          delay(300);
          NewTone(buzzer, 200, 200);
          delay(300);
          goto retry;
        }
      }
    }
  }
}
void changePassword() {
retry:
  tempPassword = "";
  lcd.clear();
  i = 1;
  while (!changedPassword) {
    keypressed = myKeypad.getKey();
    lcd.setCursor(0, 0);
    lcd.print("CURRENT PASSWORD");
    lcd.setCursor(0, 1);
    lcd.print(">");
    if (keypressed != NO_KEY) {
      if (keypressed == '0' || keypressed == '1' || keypressed == '2' || keypressed == '3' ||
          keypressed == '4' || keypressed == '5' || keypressed == '6' || keypressed == '7' ||
          keypressed == '8' || keypressed == '9' ) {
        tempPassword += keypressed;
        lcd.setCursor(i, 1);
        lcd.print("*");
        i++;
        NewTone(buzzer, 800, 200);
      }
      else if (keypressed == '#') {
        break;
      }
      else if (keypressed == '*') {
        i = 1;
        if (password == tempPassword) {
          storedPassword = false;
          NewTone(buzzer, 500, 200);
          newPassword();
          break;
        }
        else {
          tempPassword = "";
          NewTone(buzzer, 500, 200);
          delay(300);
          NewTone(buzzer, 500, 200);
          delay(300);
          goto retry;
        }
      }
    }
  }
}
String firstpass;

void Sound() {
  tone(speakerPin, currentPitch, 10);
  currentPitch += pitchStep;
  if (currentPitch >= pitchHigh) {
    pitchStep = -pitchStep;
  }
  else if (currentPitch <= pitchLow) {
    pitchStep = -pitchStep;
  }
  delay(delayTime);
}

//Setup new password
void newPassword() {
  tempPassword = "";
  changedPassword = false;
  lcd.clear();
  i = 1;
  while (!storedPassword) {
    keypressed = myKeypad.getKey();
    if (doublecheck == 0) {
      lcd.setCursor(0, 0);
      lcd.print("SET NEW PASSWORD");
      lcd.setCursor(0, 1);
      lcd.print(">");
    }
    else {
      lcd.setCursor(0, 0);
      lcd.print("One more time...");
      lcd.setCursor(0, 1);
      lcd.print(">");
    }
    if (keypressed != NO_KEY) {
      if (keypressed == '0' || keypressed == '1' || keypressed == '2' || keypressed == '3' ||
          keypressed == '4' || keypressed == '5' || keypressed == '6' || keypressed == '7' ||
          keypressed == '8' || keypressed == '9' ) {
        tempPassword += keypressed;
        lcd.setCursor(i, 1);
        lcd.print("*");
        i++;
        NewTone(buzzer, 800, 200);
      }
      else if (keypressed == '#') {
        break;
      }
      else if (keypressed == '*') {
        if (doublecheck == 0) {
          firstpass = tempPassword;
          doublecheck = 1;
          newPassword();
        }
        if (doublecheck == 1) {
          doublecheck = 0;
          if (firstpass == tempPassword) {
            i = 1;
            firstpass = "";
            password = tempPassword;
            tempPassword = "";
            lcd.setCursor(0, 0);
            lcd.print("PASSWORD CHANGED");
            lcd.setCursor(0, 1);
            lcd.print("----------------");
            storedPassword = true;
            NewTone(buzzer, 500, 400);
            delay(2000);
            lcd.clear();
            break;
          }
          else {
            firstpass = "";
            newPassword();
          }


        }
      }
    }
  }
}

Advertisement

Gebruikers-avatar
Berichten: 1792
Geregistreerd: 06 Aug 2016, 01:03

Re: Deze code wil ik invoegen in mijn alarm instalatie

Berichtdoor Koepel » 06 Jan 2018, 13:41

Dat is een goede oplossing.

De NewPing gebruikt Timer2.
De NewTone gebruikt Timer1. Dat gaat dus samen, zoals hier beschreven is: https://bitbucket.org/teckel12/arduino-new-ping/wiki/Home#!timer-2-conflict.
Ik heb veel vertrouwen in de code van Tim Eckel, ik gebruik zijn libraries in meerdere projecten.

Je sketch heb ik niet bekeken, maar ik zag labels "retry:" en een "goto" daar naar toe.
Dat is volstrekt legaal in de 'c' taal, maar onder programmeurs betekent dat een tekortkoming in de manier waarom de code is geschreven. De logische indeling van de code wordt doorbroken door een "goto". Daarom zal iedere programmeur tot het uiterste toe proberen om een "goto" te vermijden.

Berichten: 49
Geregistreerd: 09 Jun 2017, 01:59

Re: Deze code wil ik invoegen in mijn alarm instalatie

Berichtdoor Dino » 09 Jan 2018, 14:42

Heb newping geinstaleerd en oude verwijderd maar nog steeds een conflict met

Archiving built core (caching) in: C:\Users\Benny\AppData\Local\Temp\arduino_cache_727401\core\core_arduino_avr_uno_034037dd6c8b635230ff161f53a473d9.a
Tone.cpp.o (symbol from plugin): In function `timer0_pin_port':

Berichten: 2435
Geregistreerd: 16 Okt 2013, 14:31
Woonplaats: s hertogenbosch

Re: Deze code wil ik invoegen in mijn alarm instalatie

Berichtdoor shooter » 10 Jan 2018, 15:46

je gebruikt iets dubbel in de functie vector_7 bijvoorbeeld, maar die zit in een lib, dus niet zichtbaar voor ons.
paul deelen
shooter@home.nl

Gebruikers-avatar
Berichten: 1792
Geregistreerd: 06 Aug 2016, 01:03

Re: Deze code wil ik invoegen in mijn alarm instalatie

Berichtdoor Koepel » 10 Jan 2018, 18:46

Gebruik je overal NewTone ? of toch nog ergens een tone() ?

Berichten: 49
Geregistreerd: 09 Jun 2017, 01:59

Re: Deze code wil ik invoegen in mijn alarm instalatie

Berichtdoor Dino » 12 Jan 2018, 13:55

Dank alle heb hem gevonden mijn fout heb 1 keer Tone gebruikte en de rest NewTone
opegelsot

Berichten: 49
Geregistreerd: 09 Jun 2017, 01:59

Re: Deze code wil ik invoegen in mijn alarm instalatie

Berichtdoor Dino » 02 Feb 2018, 16:59

Geachte


kom er niet meer uit gebruik de script nergens fout melding alleen de afstand sensor draait niet in systeem mee.
van alles geprobeerd qua script het zou moeten werken .
het gaat om de regel
if (curr_distanse < (MAX_DISTANCE)) {
alarmFunction();
hier zeg ik als de meting kleiner is dan 2000 moet je alarm slaan .
maar gebeurd niks .



Code: Alles selecteren
#include <Wire.h>
#include <LiquidCrystal_I2C.h>
#include <Keypad_I2C.h>
#include <Keypad.h>
#include <NewPing.h>
#include "NewTone.h"
#define PING_PIN  10
#define MAX_DISTANCE 2000

const int pitchLow = 200;
const int pitchHigh = 1000;
int pitchStep = 10;
int currentPitch;
int delayTime;
const byte numRows = 4;
const byte numCols = 4;
char keypressed;
char keymap[numRows][numCols] =
{
  {'1', '2', '3', 'A'},
  {'4', '5', '6', 'B'},
  {'7', '8', '9', 'C'},
  {'*', '0', '#', 'D'}
};
int adress = 0x38;
byte rowPins[numRows] = {0, 1, 2, 3};
byte colPins[numCols] = {4, 5, 6, 7};

Keypad_I2C myKeypad = Keypad_I2C(makeKeymap(keymap), rowPins, colPins, numRows, numCols, adress);
NewPing sonar(PING_PIN, PING_PIN, MAX_DISTANCE);

const int buzzer = A1;
const int Slaapkamer = 2;
const int Woonkamer = 3;
const int Keuken = 4;
//const int Led = 5;//reserver
const int RedLed = 6;
const int BleuLed = 7;
const int GreenLed = 8;
const int speakerPin = 9;
const int Relay = 12;

LiquidCrystal_I2C lcd(0x27, 16, 2);

String password = "1958";
String tempPassword = "";
int doublecheck;
boolean armed = false;
boolean input_pass;
boolean storedPassword = true;
boolean changedPassword = false;
boolean checkPassword = false;
int distance;
int i = 1;


void setup() {
  Serial.begin(115200);
  lcd.begin();
  lcd.backlight();
  myKeypad.begin();
  pinMode(Woonkamer, INPUT);
  pinMode(Slaapkamer, INPUT);
  pinMode(Keuken , INPUT);
  pinMode(Relay, OUTPUT);
  pinMode(RedLed , OUTPUT);
  pinMode(GreenLed , OUTPUT);
  pinMode(BleuLed , OUTPUT);
  currentPitch = pitchLow;
  delayTime = 10;

}

void loop() {
  digitalWrite(GreenLed, HIGH);
  if (armed) {
    digitalWrite(RedLed, HIGH);
    systemIsArmed();
  }
  else if (!armed) {
    digitalWrite(RedLed, LOW);
    systemIsUnarmed();
  }
}

void systemIsUnarmed() {
  int screenMsg = 0;
  lcd.clear();
  unsigned long previousMillis = 0;
  const long interval = 5000;

  while (!armed) {
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis;
      if (screenMsg == 0) {
        lcd.setCursor(0, 0);
        lcd.print("SYSTEM ALARM OFF");
        lcd.setCursor(0, 1);
        lcd.print("----------------");
        digitalWrite(Relay, LOW);
        screenMsg = 1;
      }
      else {
        lcd.setCursor(0, 0);
        lcd.print("A to arm        ");
        lcd.setCursor(0, 1);
        lcd.print("B to change pass");
        screenMsg = 0;
      }
    }
    keypressed = myKeypad.getKey();
    if (keypressed == 'A') {
      NewTone(buzzer, 500, 200);
      systemIsArmed();
    }
    else if (keypressed == 'B') {
      doublecheck = 0;
      NewTone(buzzer, 500, 200);
      digitalWrite(BleuLed, HIGH);
      storedPassword = false;
      if (!changedPassword) {
        changePassword();
        digitalWrite(BleuLed , LOW);
      }
    }
  }
}

//While system is armed
void systemIsArmed() {
  lcd.clear();
  int count = 10;
  unsigned long previousMillis = 0;
  const long interval = 1000;
  while (!armed) {
    lcd.setCursor(0, 0);
    lcd.print(" SYSTEM WILL BE ");
    lcd.setCursor(0, 1);
    lcd.print("   ARMED IN ");
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis;

      if (count > 1) {
        count--;
      }
      else {
        armed = true;
        break;
      }
    }
    lcd.setCursor(12, 1);
    lcd.print(count);
  }
  while (armed) {
    lcd.setCursor(0, 0);
    lcd.print("SYSTEM IS ARMED!");
    lcd.setCursor(0, 1);
    lcd.print("----------------");
    int Kamer = digitalRead(Woonkamer);
    int SLKamer = digitalRead(Slaapkamer);
    int keuken = digitalRead(Keuken);
    int curr_distanse = sonar.ping_cm();
 
  if (curr_distanse < (MAX_DISTANCE)) {
       alarmFuncunction();
    }
    if (SLKamer == HIGH) {
      lcd.clear();
      lcd.print("Slaapkamer");
      delay(1000);
      alarmFunction();
    }
    if (Kamer == HIGH) {
      lcd.clear();
      lcd.print("Kamer");
      alarmFunction();
     
    }
    if (keuken == HIGH) {
      lcd.clear();
      lcd.print("Keuken");
      delay(1000);
      alarmFunction();
    }
  }
}

void unlockPassword() {
  int count = 21;
retry:
  tempPassword = "";
  lcd.clear();
  i = 6;
  unsigned long previousMillis = 0;
  const long interval = 1000;
  boolean buzzerState = false;
  while (!checkPassword) {
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis;
      if (!buzzerState) {
        NewTone(buzzer, 700);
        buzzerState = true;
      }
      else {
        noNewTone(buzzer);
        buzzerState = false;
      }
      if (count > 0) {
        count--;
      }
      else {
        alarmFunction();
        break;
      }
    }
    keypressed = myKeypad.getKey();
    lcd.setCursor(0, 0);
    lcd.print("ALARM IN: ");
    if (count >= 10) {
      lcd.setCursor(14, 0);
      lcd.print(count);
    }
    else {
      lcd.setCursor(14, 0);
      lcd.print(" ");
      lcd.print(count);
    }
    lcd.setCursor(0, 1);
    lcd.print("PASS>");


    if (keypressed != NO_KEY) {
      if (keypressed == '0' || keypressed == '1' || keypressed == '2' || keypressed == '3' ||
          keypressed == '4' || keypressed == '5' || keypressed == '6' || keypressed == '7' ||
          keypressed == '8' || keypressed == '9' ) {
        tempPassword += keypressed;
        lcd.setCursor(i, 1);
        lcd.print("*");
        i++;
        NewTone(buzzer, 500, 200);
      }
      else if (keypressed == '*') {
        if (password == tempPassword) {
          armed = false;
          NewTone(buzzer, 700, 500);
          break;
        }
        else {
          tempPassword = "";
          NewTone(buzzer, 200, 200);
          delay(300);
          NewTone(buzzer, 200, 200);
          delay(300);
          goto retry;
        }
      }
    }
  }

}

//Alarm
void alarmFunction() {
  for (int i = 0; i < 10; i++) {
    digitalWrite(Relay, HIGH);
    delay(1000);
    digitalWrite(Relay, LOW);
    delay(1000);
  }
retry:
  tempPassword = "";
  lcd.clear();
  i = 6;
  unsigned long previousMillis = 0;
  const long interval = 500;
  boolean buzzerState = false;
  while (!checkPassword) {
    unsigned long currentMillis = millis();
    if (currentMillis - previousMillis >= interval) {
      previousMillis = currentMillis;
      if (!buzzerState) {
        NewTone(buzzer, 700);
        buzzerState = true;
      }
      else {
        noNewTone(buzzer);
        buzzerState = false;
      }
    }
    keypressed = myKeypad.getKey();
    lcd.setCursor(0, 0);
    lcd.print("  !!! ALARM !!! ");
    lcd.setCursor(0, 1);
    lcd.print("PASS>");
    if (keypressed != NO_KEY) {     //Accept only numbers and *
      if (keypressed == '0' || keypressed == '1' || keypressed == '2' || keypressed == '3' ||
          keypressed == '4' || keypressed == '5' || keypressed == '6' || keypressed == '7' ||
          keypressed == '8' || keypressed == '9' ) {
        tempPassword += keypressed;
        lcd.setCursor(i, 1);
        lcd.print("*");
        i++;
      }
      else if (keypressed == '*') {
        if (password == tempPassword) {
          armed = false;
          NewTone(buzzer, 700, 500);
          break;
        }
        else {
          tempPassword = "";
          NewTone(buzzer, 200, 200);
          delay(300);
          NewTone(buzzer, 200, 200);
          delay(300);
          goto retry;
        }
      }
    }
  }
}
void changePassword() {
retry:
  tempPassword = "";
  lcd.clear();
  i = 1;
  while (!changedPassword) {
    keypressed = myKeypad.getKey();
    lcd.setCursor(0, 0);
    lcd.print("CURRENT PASSWORD");
    lcd.setCursor(0, 1);
    lcd.print(">");
    if (keypressed != NO_KEY) {
      if (keypressed == '0' || keypressed == '1' || keypressed == '2' || keypressed == '3' ||
          keypressed == '4' || keypressed == '5' || keypressed == '6' || keypressed == '7' ||
          keypressed == '8' || keypressed == '9' ) {
        tempPassword += keypressed;
        lcd.setCursor(i, 1);
        lcd.print("*");
        i++;
        NewTone(buzzer, 800, 200);
      }
      else if (keypressed == '#') {
        break;
      }
      else if (keypressed == '*') {
        i = 1;
        if (password == tempPassword) {
          storedPassword = false;
          NewTone(buzzer, 500, 200);
          newPassword();
          break;
        }
        else {
          tempPassword = "";
          NewTone(buzzer, 500, 200);
          delay(300);
          NewTone(buzzer, 500, 200);
          delay(300);
          goto retry;
        }
      }
    }
  }
}
String firstpass;

void Sound() {
  NewTone(speakerPin, currentPitch, 10);
  currentPitch += pitchStep;
  if (currentPitch >= pitchHigh) {
    pitchStep = -pitchStep;
  }
  else if (currentPitch <= pitchLow) {
    pitchStep = -pitchStep;
  }
  delay(delayTime);
}

//Setup new password
void newPassword() {
  tempPassword = "";
  changedPassword = false;
  lcd.clear();
  i = 1;
  while (!storedPassword) {
    keypressed = myKeypad.getKey();
    if (doublecheck == 0) {
      lcd.setCursor(0, 0);
      lcd.print("SET NEW PASSWORD");
      lcd.setCursor(0, 1);
      lcd.print(">");
    }
    else {
      lcd.setCursor(0, 0);
      lcd.print("One more time...");
      lcd.setCursor(0, 1);
      lcd.print(">");
    }
    if (keypressed != NO_KEY) {
      if (keypressed == '0' || keypressed == '1' || keypressed == '2' || keypressed == '3' ||
          keypressed == '4' || keypressed == '5' || keypressed == '6' || keypressed == '7' ||
          keypressed == '8' || keypressed == '9' ) {
        tempPassword += keypressed;
        lcd.setCursor(i, 1);
        lcd.print("*");
        i++;
        NewTone(buzzer, 800, 200);
      }
      else if (keypressed == '#') {
        break;
      }
      else if (keypressed == '*') {
        if (doublecheck == 0) {
          firstpass = tempPassword;
          doublecheck = 1;
          newPassword();
        }
        if (doublecheck == 1) {
          doublecheck = 0;
          if (firstpass == tempPassword) {
            i = 1;
            firstpass = "";
            password = tempPassword;
            tempPassword = "";
            lcd.setCursor(0, 0);
            lcd.print("PASSWORD CHANGED");
            lcd.setCursor(0, 1);
            lcd.print("----------------");
            storedPassword = true;
            NewTone(buzzer, 500, 400);
            delay(2000);
            lcd.clear();
            break;
          }
          else {
            firstpass = "";
            newPassword();
          }


        }
      }
    }
  }
}

Gebruikers-avatar
Berichten: 1792
Geregistreerd: 06 Aug 2016, 01:03

Re: Deze code wil ik invoegen in mijn alarm instalatie

Berichtdoor Koepel » 04 Feb 2018, 03:26

Sorry, maar ik kan er niet veel mee. De structuur van de code is moeilijk te doorgronden. Misschien dat iemand anders er meer mee kan.

In de loop() zijn er twee functies, die zelf ook while-loops hebben waar ze in kunnen blijven hangen.
Ik zie verder allerlei code waarvan ik niet weet wat je er mee wilt. Eigenlijk begrijp ik alleen de code in de setup() functie.

Dit gebeurt er als je geen vast plan volgt. Daarom is het belangrijk om een diagram te maken met de logica van wat je wilt.

Gebruikers-avatar
Berichten: 255
Geregistreerd: 15 Nov 2015, 11:54

Re: Deze code wil ik invoegen in mijn alarm instalatie

Berichtdoor Gij Kieken » 04 Feb 2018, 13:52

Een paar println toevoegen aan de code (Debug)
bijvoorbeeld na, int curr_distanse

en zie wat er uit komt.

Terug naar Arduino software

Wie is er online?

Gebruikers in dit forum: Geen geregistreerde gebruikers en 3 gasten