› PLCGurus.NET Live & Interactive Forum › PLC Questions and Answers › Miscellaneous Automation Controllers › Coding
- This topic has 2 replies, 2 voices, and was last updated 5 years, 1 month ago by
tfgmedia_admin.
- AuthorPosts
- August 27, 2021 at 6:21 pm #20284
wsmith1126ParticipantKarma: 42Rank: Padawan<div class=”container posts”>
<div class=”row”><section id=”topic” class=”topic-area” data-topic-id=”899929″>
<div class=”posts-wrapper”>
<div id=”ember682″ class=”ember-view”>
<div class=”post-stream”>
<div class=”topic-post clearfix topic-owner current-user-post regular”><article id=”post_1″ class=”boxed onscreen-post” role=”region” aria-label=”post #1″ data-post-id=”6062447″ data-topic-id=”899929″ data-user-id=”1100689″>
<div class=”row”>
<div class=”topic-body clearfix”>
<div class=”regular contents”>
<div class=”cooked”>Can someone please tell me why this won’t verify, I have worked on this all day and still get the same error ‘getDistance’ was not declared in this scope
<span class=”hashtag”>#include</span> <MFRC522.h>
<span class=”hashtag”>#include</span> <SPI.h>
<span class=”hashtag”>#include</span> <LiquidCrystal.h>
<span class=”hashtag”>#include</span> <Keypad.h><span class=”hashtag”>#define</span> buzzer 8
<span class=”hashtag”>#define</span> trigPin 10
<span class=”hashtag”>#define</span> echoPin 9<span class=”hashtag”>#define</span> RST_PIN 12 // Configurable, see typical pin layout above
<span class=”hashtag”>#define</span> SS_PIN 11 // Configurable, see typical pin layout aboveMFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
/* Set your new UID here! */
<span class=”hashtag”>#define</span> NEW_UID {0xDE, 0xAD, 0xBE, 0xEF}MFRC522::MIFARE_Key key;
long duration;
int distance, initialDistance, currentDistance, i;
int screenOffMsg =0;
String password=”1234″;
String tempPassword;
boolean activated = false; // State of the alarm
boolean isActivated;
boolean activateAlarm = false;
boolean alarmActivated = false;
boolean enteredPassword; // State of the entered password to stop the alarm
boolean passChangeMode = false;
boolean passChanged = false;const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keypressed;
//define the cymbols on the buttons of the keypads
char keyMap[ROWS][COLS] = {
{‘1′,’2′,’3′,’A’},
{‘4′,’5′,’6′,’B’},
{‘7′,’8′,’9′,’C’},
{‘*’,’0′,’#’,’D’}
};
byte rowPins[ROWS] = {14, 15, 16, 17}; //Row pinouts of the keypad
byte colPins[COLS] = {18, 19, 20, 21}; //Column pinouts of the keypadKeypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, ROWS, COLS);
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs=2,enable=3,d4=4,d5=5,d6=,d7=7)void setup() {
//
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print(“hello, world!”);pinMode(buzzer, OUTPUT); // Set buzzer as an output
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an InputSerial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println(F(“Warning: this example overwrites the UID of your UID changeable card, use with care!”));// Prepare key – all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
}// Setting the UID can be as simple as this:
//void loop() {
// byte newUid = NEW_UID;
// if ( mfrc522.MIFARE_SetUid(newUid, (byte)4, true) ) {
// Serial.println(“Wrote new UID to card.”);
// }
// delay(1000);
//}// But of course this is a more proper approach
void loop() {// Look for new cards, and select one if present
if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
delay(50);
return;
}// Now a card is selected. The UID and SAK is in mfrc522.uid.
// Dump UID
Serial.print(F(“Card UID:”));
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? ” 0″ : ” “);
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.println();// Dump PICC type
// MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
// Serial.print(F(“PICC type: “));
// Serial.print(mfrc522.PICC_GetTypeName(piccType));
// Serial.print(F(” (SAK “));
// Serial.print(mfrc522.uid.sak);
// Serial.print(“)\r\n”);
// if ( piccType != MFRC522::PICC_TYPE_MIFARE_MINI
// && piccType != MFRC522::PICC_TYPE_MIFARE_1K
// && piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
// Serial.println(F(“This sample only works with MIFARE Classic cards.”));
// return;
// }// Set new UID
byte newUid = NEW_UID;
if ( mfrc522.MIFARE_SetUid(newUid, (byte)4, true) ) {
Serial.println(F(“Wrote new UID to card.”));
}// Halt PICC and re-select it so DumpToSerial doesn’t get confused
mfrc522.PICC_HaltA();
if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
return;
}// Dump the new memory contents
Serial.println(F(“New UID and contents:”));
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));delay(2000);
if (activateAlarm);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(“Alarm will be”);
lcd.setCursor(0,1);
lcd.print(“activated in”);<button class="btn nohighlight copy-cmd"></button><code class="hljs perl"><span class="hljs-keyword">int</span> countdown = <span class="hljs-number">8</span>; <span class="hljs-regexp">//</span> <span class="hljs-number">8</span> seconds count down before activating the <span class="hljs-keyword">alarm</span> <span class="hljs-keyword">while</span> (countdown != <span class="hljs-number">0</span>) { lcd.setCursor(<span class="hljs-number">13</span>,<span class="hljs-number">1</span>); lcd.<span class="hljs-keyword">print</span>(countdown); countdown--; tone(buzzer, <span class="hljs-number">100</span>, <span class="hljs-number">100</span>); delay(<span class="hljs-number">1000</span>); } lcd.clear(); lcd.setCursor(<span class="hljs-number">0</span>,<span class="hljs-number">0</span>); lcd.<span class="hljs-keyword">print</span>(<span class="hljs-string">"Alarm Activated!"</span>);initialDistance = getDistance();
activateAlarm = false;
alarmActivated = true;
}
if (alarmActivated == true);
currentDistance = getDistance() + 10;
if ( currentDistance < initialDistance);
tone(buzzer, 1000); // Send 1KHz sound signal
lcd.clear();
enterPassword();if (!alarmActivated);
if (screenOffMsg == 0 );
lcd.clear();
lcd.setCursor(0,0);
lcd.print(“A – Activate”);
lcd.setCursor(0,1);
lcd.print(“B – Change Pass”);
screenOffMsg = 1;<button class="btn nohighlight copy-cmd"></button><code class="hljs php">keypressed = myKeypad.getKey(); <span class="hljs-keyword">if</span> (keypressed ==<span class="hljs-string">'A'</span>); <span class="hljs-comment">//If A is pressed, activate the alarm</span> tone(buzzer, <span class="hljs-number">1000</span>, <span class="hljs-number">200</span>); activateAlarm = <span class="hljs-literal">true</span>; } <span class="hljs-keyword">else</span> <span class="hljs-keyword">if</span> (keypressed ==<span class="hljs-string">'B'</span>) { lcd.clear(); <span class="hljs-keyword">int</span> i=<span class="hljs-number">1</span>; tone(buzzer, <span class="hljs-number">2000</span>, <span class="hljs-number">100</span>); tempPassword = <span class="hljs-string">""</span>; lcd.setCursor(<span class="hljs-number">0</span>,<span class="hljs-number">0</span>); lcd.<span class="hljs-keyword">print</span>(<span class="hljs-string">"Enter Password"</span>); lcd.setCursor(<span class="hljs-number">0</span>,<span class="hljs-number">1</span>); lcd.<span class="hljs-keyword">print</span>(<span class="hljs-string">">"</span>); passChangeMode = <span class="hljs-literal">true</span>; passChanged = <span class="hljs-literal">true</span>; <span class="hljs-keyword">while</span>(passChanged) { keypressed = myKeypad.getKey(); <span class="hljs-keyword">if</span> (keypressed != NO_KEY){ <span class="hljs-keyword">if</span> (keypressed == <span class="hljs-string">'0'</span> || keypressed == <span class="hljs-string">'1'</span> || keypressed == <span class="hljs-string">'2'</span> || keypressed == <span class="hljs-string">'3'</span> || keypressed == <span class="hljs-string">'4'</span> || keypressed == <span class="hljs-string">'5'</span> || keypressed == <span class="hljs-string">'6'</span> || keypressed == <span class="hljs-string">'7'</span> || keypressed == <span class="hljs-string">'8'</span> || keypressed == <span class="hljs-string">'9'</span> ) { tempPassword += keypressed; lcd.setCursor(i,<span class="hljs-number">1</span>); lcd.<span class="hljs-keyword">print</span>(<span class="hljs-string">"*"</span>); i++; tone(buzzer, <span class="hljs-number">2000</span>, <span class="hljs-number">100</span>); } } <span class="hljs-keyword">if</span> (i > <span class="hljs-number">5</span> || keypressed == <span class="hljs-string">'#'</span>) { tempPassword = <span class="hljs-string">""</span>; i=<span class="hljs-number">1</span>; lcd.clear(); lcd.setCursor(<span class="hljs-number">0</span>,<span class="hljs-number">0</span>); lcd.<span class="hljs-keyword">print</span>(<span class="hljs-string">"Enter Password"</span>); lcd.setCursor(<span class="hljs-number">0</span>,<span class="hljs-number">1</span>); lcd.<span class="hljs-keyword">print</span>(<span class="hljs-string">">"</span>); } <span class="hljs-keyword">if</span> ( keypressed == <span class="hljs-string">'*'</span>) { i=<span class="hljs-number">1</span>; tone(buzzer, <span class="hljs-number">2000</span>, <span class="hljs-number">100</span>); <span class="hljs-keyword">if</span> (password == tempPassword) { tempPassword=<span class="hljs-string">""</span>; lcd.clear(); lcd.setCursor(<span class="hljs-number">0</span>,<span class="hljs-number">0</span>); lcd.<span class="hljs-keyword">print</span>(<span class="hljs-string">"Set New Password"</span>); lcd.setCursor(<span class="hljs-number">0</span>,<span class="hljs-number">1</span>); lcd.<span class="hljs-keyword">print</span>(<span class="hljs-string">">"</span>); <span class="hljs-keyword">while</span>(passChangeMode) { keypressed = myKeypad.getKey(); <span class="hljs-keyword">if</span> (keypressed != NO_KEY){ <span class="hljs-keyword">if</span> (keypressed == <span class="hljs-string">'0'</span> || keypressed == <span class="hljs-string">'1'</span> || keypressed == <span class="hljs-string">'2'</span> || keypressed == <span class="hljs-string">'3'</span> || keypressed == <span class="hljs-string">'4'</span> || keypressed == <span class="hljs-string">'5'</span> || keypressed == <span class="hljs-string">'6'</span> || keypressed == <span class="hljs-string">'7'</span> || keypressed == <span class="hljs-string">'8'</span> || keypressed == <span class="hljs-string">'9'</span> ) { tempPassword += keypressed; lcd.setCursor(i,<span class="hljs-number">1</span>); lcd.<span class="hljs-keyword">print</span>(<span class="hljs-string">"*"</span>); i++; tone(buzzer, <span class="hljs-number">2000</span>, <span class="hljs-number">100</span>); } } <span class="hljs-keyword">if</span> (i > <span class="hljs-number">5</span> || keypressed == <span class="hljs-string">'#'</span>) { tempPassword = <span class="hljs-string">""</span>; i=<span class="hljs-number">1</span>; tone(buzzer, <span class="hljs-number">2000</span>, <span class="hljs-number">100</span>); lcd.clear(); lcd.setCursor(<span class="hljs-number">0</span>,<span class="hljs-number">0</span>); lcd.<span class="hljs-keyword">print</span>(<span class="hljs-string">"Set New Password"</span>); lcd.setCursor(<span class="hljs-number">0</span>,<span class="hljs-number">1</span>); lcd.<span class="hljs-keyword">print</span>(<span class="hljs-string">">"</span>); } <span class="hljs-keyword">if</span> ( keypressed == <span class="hljs-string">'*'</span>) { i=<span class="hljs-number">1</span>; tone(buzzer, <span class="hljs-number">2000</span>, <span class="hljs-number">100</span>); password = tempPassword; passChangeMode = <span class="hljs-literal">false</span>; passChanged = <span class="hljs-literal">false</span>; screenOffMsg = <span class="hljs-number">0</span>; } } } } }}
}
}
void
enterPassword() {
int k=5;
tempPassword = “”;
activated = true;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(” *** ALARM *** “);
lcd.setCursor(0,1);
lcd.print(“Pass>”);
while(activated) {
keypressed = myKeypad.getKey();
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(k,1);
lcd.print(““);
k++;
}
}
if (k > 9 || keypressed == ‘#’) {
tempPassword = “”;
k=5;
lcd.clear();
lcd.setCursor(0,0);
lcd.print(” *** ALARM *** “);
lcd.setCursor(0,1);
lcd.print(“Pass>”);
}
if ( keypressed == ‘‘) {
if ( tempPassword == password ) {
activated = false;
alarmActivated = false;
noTone(buzzer);
screenOffMsg = 0;
}
else if (tempPassword != password) {
lcd.setCursor(0,1);
lcd.print(“Wrong! Try Again”);
delay(2000);
lcd.clear();
lcd.setCursor(0,0);
lcd.print(” *** ALARM *** “);
lcd.setCursor(0,1);
lcd.print(“Pass>”);
}
}
}
}
// Custom function for the Ultrasonic sensor
long getDistance(){
//int i=10;//while( i<=10 ) {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration*0.034/2;
//sumDistance += distance;
//}
//int averageDistance= sumDistance/10;
return distance;
}</div>
<section class=”post-menu-area clearfix”><nav class=”post-controls expanded”></nav></section></div>
</div>
</div>
</article></div>
</div>
</div>
</div>
</section></div>
</div>
<div class=” suggested-topics-wrapper”>
<div id=”suggested-topics” class=”suggested-topics” role=”complementary” aria-labelledby=”suggested-topics-title”>
<div class=”topics”>
<div id=”ember712″ class=”ember-view”>
<div id=”ember713″ class=”loading-container ember-view”></div>
</div>
</div>
</div>
</div>August 27, 2021 at 9:50 pm #20285
wsmith1126ParticipantKarma: 42Rank: Padawan[code]
#include <MFRC522.h>
#include <SPI.h>
#include <LiquidCrystal.h>
#include <Keypad.h>#define buzzer 8
#define trigPin 10
#define echoPin 9#define RST_PIN 12 // Configurable, see typical pin layout above
#define SS_PIN 11 // Configurable, see typical pin layout aboveMFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance
/* Set your new UID here! */
#define NEW_UID {0xDE, 0xAD, 0xBE, 0xEF}MFRC522::MIFARE_Key key;
long duration;
int distance, initialDistance, currentDistance, i;
int screenOffMsg = 0;
String password = “1234”;
String tempPassword;
boolean activated = false; // State of the alarm
boolean isActivated;
boolean activateAlarm = false;
boolean alarmActivated = false;
boolean enteredPassword; // State of the entered password to stop the alarm
boolean passChangeMode = false;
boolean passChanged = false;const byte ROWS = 4; //four rows
const byte COLS = 4; //four columns
char keypressed;
//define the cymbols on the buttons of the keypads
char keyMap[ROWS][COLS] = {
{‘1’, ‘2’, ‘3’, ‘A’},
{‘4’, ‘5’, ‘6’, ‘B’},
{‘7’, ‘8’, ‘9’, ‘C’},
{‘*’, ‘0’, ‘#’, ‘D’}
};
byte rowPins[ROWS] = {14, 15, 16, 17}; //Row pinouts of the keypad
byte colPins[COLS] = {18, 19, 20, 21}; //Column pinouts of the keypadKeypad myKeypad = Keypad( makeKeymap(keyMap), rowPins, colPins, ROWS, COLS);
LiquidCrystal lcd(2, 3, 4, 5, 6, 7); // Creates an LC object. Parameters: (rs=2,enable=3,d4=4,d5=5,d6=,d7=7)void setup() {
//
// set up the LCD’s number of columns and rows:
lcd.begin(16, 2);
// Print a message to the LCD.
lcd.print(“hello, world!”);pinMode(buzzer, OUTPUT); // Set buzzer as an output
pinMode(trigPin, OUTPUT); // Sets the trigPin as an Output
pinMode(echoPin, INPUT); // Sets the echoPin as an InputSerial.begin(9600); // Initialize serial communications with the PC
while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4)
SPI.begin(); // Init SPI bus
mfrc522.PCD_Init(); // Init MFRC522 card
Serial.println(F(“Warning: this example overwrites the UID of your UID changeable card, use with care!”));// Prepare key – all keys are set to FFFFFFFFFFFFh at chip delivery from the factory.
for (byte i = 0; i < 6; i++) {
key.keyByte[i] = 0xFF;
}
}// Setting the UID can be as simple as this:
//void loop() {
// byte newUid[] = NEW_UID;
// if ( mfrc522.MIFARE_SetUid(newUid, (byte)4, true) ) {
// Serial.println(“Wrote new UID to card.”);
// }
// delay(1000);
//}// But of course this is a more proper approach
void loop() {// Look for new cards, and select one if present
if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
delay(50);
return;
}// Now a card is selected. The UID and SAK is in mfrc522.uid.
// Dump UID
Serial.print(F(“Card UID:”));
for (byte i = 0; i < mfrc522.uid.size; i++) {
Serial.print(mfrc522.uid.uidByte[i] < 0x10 ? ” 0″ : ” “);
Serial.print(mfrc522.uid.uidByte[i], HEX);
}
Serial.println();// Dump PICC type
// MFRC522::PICC_Type piccType = mfrc522.PICC_GetType(mfrc522.uid.sak);
// Serial.print(F(“PICC type: “));
// Serial.print(mfrc522.PICC_GetTypeName(piccType));
// Serial.print(F(” (SAK “));
// Serial.print(mfrc522.uid.sak);
// Serial.print(“)\r\n”);
// if ( piccType != MFRC522::PICC_TYPE_MIFARE_MINI
// && piccType != MFRC522::PICC_TYPE_MIFARE_1K
// && piccType != MFRC522::PICC_TYPE_MIFARE_4K) {
// Serial.println(F(“This sample only works with MIFARE Classic cards.”));
// return;
// }// Set new UID
byte newUid[] = NEW_UID;
if ( mfrc522.MIFARE_SetUid(newUid, (byte)4, true) ) {
Serial.println(F(“Wrote new UID to card.”));
}// Halt PICC and re-select it so DumpToSerial doesn’t get confused
mfrc522.PICC_HaltA();
if ( ! mfrc522.PICC_IsNewCardPresent() || ! mfrc522.PICC_ReadCardSerial() ) {
return;
}// Dump the new memory contents
Serial.println(F(“New UID and contents:”));
mfrc522.PICC_DumpToSerial(&(mfrc522.uid));delay(2000);
if (activateAlarm);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Alarm will be”);
lcd.setCursor(0, 1);
lcd.print(“activated in”);int countdown = 8; // 8 seconds count down before activating the alarm
while (countdown != 0) {
lcd.setCursor(13, 1);
lcd.print(countdown);
countdown–;
tone(buzzer, 100, 100);
delay(1000);
}
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Alarm Activated!”);
initialDistance = getDistance();
activateAlarm = false;
alarmActivated = true;
}
if (alarmActivated == true);
currentDistance = getDistance() + 10;
if ( currentDistance < initialDistance);
tone(buzzer, 1000); // Send 1KHz sound signal
lcd.clear();
enterPassword();if (!alarmActivated);
if (screenOffMsg == 0 );
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“A – Activate”);
lcd.setCursor(0, 1);
lcd.print(“B – Change Pass”);
screenOffMsg = 1;keypressed = myKeypad.getKey();
if (keypressed == ‘A’); //If A is pressed, activate the alarm
tone(buzzer, 1000, 200);
activateAlarm = true;
}
else if (keypressed == ‘B’) {
lcd.clear();
int i = 1;
tone(buzzer, 2000, 100);
tempPassword = “”;
lcd.setCursor(0, 0);
lcd.print(“Enter Password”);
lcd.setCursor(0, 1);
lcd.print(“>”);
passChangeMode = true;
passChanged = true;
while (passChanged) {
keypressed = myKeypad.getKey();
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++;
tone(buzzer, 2000, 100);
}
}
if (i > 5 || keypressed == ‘#’) {
tempPassword = “”;
i = 1;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Enter Password”);
lcd.setCursor(0, 1);
lcd.print(“>”);
}
if ( keypressed == ‘*’) {
i = 1;
tone(buzzer, 2000, 100);
if (password == tempPassword) {
tempPassword = “”;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Set New Password”);
lcd.setCursor(0, 1);
lcd.print(“>”);
while (passChangeMode) {
keypressed = myKeypad.getKey();
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++;
tone(buzzer, 2000, 100);
}
}
if (i > 5 || keypressed == ‘#’) {
tempPassword = “”;
i = 1;
tone(buzzer, 2000, 100);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(“Set New Password”);
lcd.setCursor(0, 1);
lcd.print(“>”);
}
if ( keypressed == ‘*’) {
i = 1;
tone(buzzer, 2000, 100);
password = tempPassword;
passChangeMode = false;
passChanged = false;
screenOffMsg = 0;
}
}
}
}
}
}
}
}
void
enterPassword() {
int k = 5;
tempPassword = “”;
activated = true;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(” *** ALARM *** “);
lcd.setCursor(0, 1);
lcd.print(“Pass>”);
while (activated) {
keypressed = myKeypad.getKey();
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(k, 1);
lcd.print(“*”);
k++;
}
}
if (k > 9 || keypressed == ‘#’) {
tempPassword = “”;
k = 5;
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(” *** ALARM *** “);
lcd.setCursor(0, 1);
lcd.print(“Pass>”);
}
if ( keypressed == ‘*’) {
if ( tempPassword == password ) {
activated = false;
alarmActivated = false;
noTone(buzzer);
screenOffMsg = 0;
}
else if (tempPassword != password) {
lcd.setCursor(0, 1);
lcd.print(“Wrong! Try Again”);
delay(2000);
lcd.clear();
lcd.setCursor(0, 0);
lcd.print(” *** ALARM *** “);
lcd.setCursor(0, 1);
lcd.print(“Pass>”);
}
}
}
}
// Custom function for the Ultrasonic sensor
long getDistance() {
//int i=10;//while( i<=10 ) {
// Clears the trigPin
digitalWrite(trigPin, LOW);
delayMicroseconds(2);
// Sets the trigPin on HIGH state for 10 micro seconds
digitalWrite(trigPin, HIGH);
delayMicroseconds(10);
digitalWrite(trigPin, LOW);
// Reads the echoPin, returns the sound wave travel time in microseconds
duration = pulseIn(echoPin, HIGH);
// Calculating the distance
distance = duration * 0.034 / 2;
//sumDistance += distance;
//}
//int averageDistance= sumDistance/10;
return distance;
}
[/code]August 27, 2021 at 10:51 pm #20286
tfgmedia_adminKeymasterHi Wayne,
You may just be missing a function declaration at the top of your file for your getDistance function. This tells the compiler a couple of things such as the functions name, return type, and parameter list. Since your getDistance function does not take any parameters you should just be able to declare it as:
long getDistance();
Try adding this below you #include and #define statements. Hopefully this will resolve.
Fred
- AuthorPosts
- You must be logged in to reply to this topic.