Pages: [1]   Go Down
Author Topic: error compiling  (Read 907 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

hi
first, sorry for my English.
I'm trying to mount a simulated bomb, when compiling I get the error "was not delcared key4 In This scope"
Code many times I've looked and can not find the problem.

Code:
/*Airsoft Bomb
Version 1.1Creators:
Chase Cooley&&&&&&&&&&&&
Joey Meyer*/

#include <Keypad.h>
#include <LiquidCrystal.h>
#include <Tone.h>
#define pound 14
Tone tone1;int Scount = 0; // count seconds
int Mcount = 0; // count minutesint Hcount =0; // count hours
int Dcount = 0; // count daysint val = 0;
long secMillis = 0; // store last time for second addlong interval = 1000; // interval for seconds
char password[4];int currentLength = 0;
int i = 0;char entered[4];
int ledPin = 3;
int ledPin2 = 4;//red lightint ledPin2 = 4; //green light

LiquidCrystal lcd(7,8,10,11,12,13);const byte ROWS = 4; //four rows
const byte COLS = 3; //three columnschar keys[ROWS][COLS] = {
char keys[ROWS][COLS] = {
{'1','2','3'},{'4','5','6'},
{'7','8','9'},{'*','0','#'}
};
byte rowPins[ROWS] = {18, 2, 14, 16}; //connect to the row pinouts of the keypadbyte colPins[COLS] = {17, 19, 15}; //connect to the column pinouts of the keypad
byte colPins[COLS] = {17, 19, 15};

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup(){
pinMode(ledPin, OUTPUT); // sets the digital pin as outputpinMode(ledPin2, OUTPUT); // sets the digital pin as output
tone1.begin(9);lcd.begin(16, 2);
Serial.begin(9600);lcd.clear();
lcd.setCursor(0,0);lcd.print("Enter Code: ");
while (currentLength < 4){
lcd.setCursor(currentLength + 6, 1);lcd.cursor();
char key = keypad.getKey();key == NO_KEY;
if (key != NO_KEY){
lcd.print(key);password[currentLength] = key;
currentLength++;delay(200);
}}
if (currentLength == 4){
lcd.noCursor();lcd.clear();
lcd.home();lcd.print("You've Entered: ");
lcd.setCursor(6,1);lcd.print(password[0]);
lcd.print(password[1]);lcd.print(password[2]);
lcd.print(password[3]);delay(3000);
lcd.clear();currentLength = 0;
}}

void loop(){
char key2 = keypad.getKey(); // get the keylcd.setCursor(0,0);
timer();if (key2 != NO_KEY)
{while (key2 == NO_KEY)
{key2 = keypad.getKey();
}if (key2 != NO_KEY)
{lcd.clear();
lcd.setCursor(0,0);lcd.print("Enter Code: ");
while (currentLength < 4){
lcd.setCursor(currentLength + 6, 1);lcd.cursor();
char key2 = keypad.getKey();if (key2 != NO_KEY)
{lcd.print(key2);
entered[currentLength] = key2;currentLength++;
delay(200);lcd.noCursor();
lcd.setCursor(currentLength + 5, 1);lcd.print("*");
lcd.setCursor(currentLength + 6, 1);lcd.cursor();
}}
if (currentLength == 4){
if (entered[0] == password[0] && entered[1] == password[1] && entered[2] == password[2] && entered[3] == password[3]){
lcd.noCursor();lcd.clear();
lcd.home();lcd.print(" Defused ");
currentLength = 0;delay(2500);
lcd.setCursor(0,1);lcd.print("Reset the Bomb");
}else
{lcd.noCursor();
lcd.clear();lcd.home();
lcd.print(" Wrong ");lcd.setCursor(0,1);
lcd.print(" Add - 1:30 ");if (Mcount < 14)
{Mcount = Mcount + 1;
}if (Scount < 59)
{Scount = Scount + 30;
}delay(1500);
currentLength = 0;}
}}
}}

void timer(){
if ( Mcount >= 15 ){
while ( Mcount >= 15){
lcd.noCursor();lcd.clear();
lcd.home();lcd.print(" !BoOm! ");
tone1.play(NOTE_A2, 200);digitalWrite(ledPin, HIGH); // sets the LED on
tone1.play(NOTE_A2, 200);delay(10); // waits for a second
digitalWrite(ledPin, LOW); // sets the LED offtone1.play(NOTE_A2, 200);
delay(10); // waits for a seconddigitalWrite(ledPin2, HIGH); // sets the LED on
tone1.play(NOTE_A2, 200);delay(10); // waits for a second
digitalWrite(ledPin2, LOW); // sets the LED offtone1.play(NOTE_A2, 200);
delay(10);// waits for a secondchar key4 = keypad.getKey();
if (key4 != NO_KEY){
while (key4 == NO_KEY){
key4 = keypad.getKey();}
if (key4 = '#'){
lcd.clear();lcd.print("Reset the Bomb");
}}
}if ( Mcount == 60) // if Mcount is 60 do this operation
{//delay (32); // good place to fine tune timing
Mcount = 0; // reset McountHcount ++;
}if (Hcount> 23)
{Dcount++;
Hcount = 0; // have to reset Hcount to "0" after 24hrs}

lcd.setCursor (0,1); // sets cursor to 2nd linelcd.print ("Timer: ");
lcd.print (Dcount);lcd.print (":");
lcd.print (Hcount);lcd.print (":");
lcd.print (Mcount);lcd.print (":");
lcd.print (Scount);
if (Scount >59) // if 60 do this operation{
Mcount ++; // add 1 to McountScount = 0; // reset Scount
//delay (58); // changes ms per min}
if (Scount < 60) // do this oper. 59 times{
unsigned long currentMillis = millis();//delay (988); // changing by one = 60 ms a min
if(currentMillis - secMillis > interval){
tone1.play(NOTE_G5, 200);secMillis = currentMillis;
Scount ++; // add 1 to ScountdigitalWrite(ledPin2, HIGH); // sets the LED on
delay(10); // waits for a seconddigitalWrite(ledPin2, LOW); // sets the LED off
delay(10); // waits for a second}
}}
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26278
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

You haven't declared a variable called "key4".
That's why the compiler is complaining.

I'm complaining about the format of your code, which the IDE's auto-format tool will help you sort out.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

thanks for your quick response but the tool tells me that there are too many brackets left and I do not do anything.
I copied the code of a web arduino and my level is still too low.
I could help a little more in the solution?
Thanks again and best regards.
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26278
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Maybe a clue as to where you copied from?
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Offline Offline
Newbie
*
Karma: 0
Posts: 7
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

http://www.instructables.com/id/Prop-bomb/
Logged

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26278
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I've never been impressed with instructables.
That one really sucks.
I'll be back soon.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26278
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Nope, can't see where they get "key4" from.
At least I can get it to format.
Code:
/*Airsoft Bomb
 Version 1.1Creators:
 Chase Cooley&&&&&&&&&&&&
 Joey Meyer*/

#include <Keypad.h>#include <LiquidCrystal.h>
#include <Tone.h>
#define pound 14

Tone tone1;
int Scount = 0; // count seconds
int Mcount = 0; // count minutesint Hcount =0; // count hours
int Dcount = 0; // count daysint val = 0;
long secMillis = 0; // store last time for second addlong interval = 1000; // interval for seconds
char password[4];
int currentLength = 0;
int i = 0;
char entered[4];
int ledPin = 3; //red lightint ledPin2 = 4; //green light

LiquidCrystal lcd(7,8,10,11,12,13);
const byte ROWS = 4; //four rows
const byte COLS = 3; //three columns
char keys[ROWS][COLS] = {
  {
    '1','2','3'  }
  ,{
    '4','5','6'  }
  ,
  {
    '7','8','9'  }
  ,{
    '*','0','#'  }
};
byte rowPins[ROWS] = {
  18, 2, 14, 16}; //connect to the row pinouts of the keypadbyte colPins[COLS] = {17, 19, 15}; //connect to the column pinouts of the keypad

Keypad keypad = Keypad( makeKeymap(keys), rowPins, colPins, ROWS, COLS );
void setup()
{
  pinMode(ledPin, OUTPUT); // sets the digital pin as outputpinMode(ledPin2, OUTPUT); // sets the digital pin as output
  tone1.begin(9);
  lcd.begin(16, 2);
  Serial.begin(9600);
  lcd.clear();
  lcd.setCursor(0,0);
  lcd.print("Enter Code: ");
  while (currentLength < 4){
    lcd.setCursor(currentLength + 6, 1);
    lcd.cursor();
    char key = keypad.getKey();
    key == NO_KEY;
    if (key != NO_KEY){
      lcd.print(key);
      password[currentLength] = key;
      currentLength++;
      delay(200);
    }
  }
  if (currentLength == 4){
    lcd.noCursor();
    lcd.clear();
    lcd.home();
    lcd.print("You've Entered: ");
    lcd.setCursor(6,1);
    lcd.print(password[0]);
    lcd.print(password[1]);
    lcd.print(password[2]);
    lcd.print(password[3]);
    delay(3000);
    lcd.clear();
    currentLength = 0;
  }
}

void loop(){
  char key2 = keypad.getKey(); // get the keylcd.setCursor(0,0);
  timer();
  if (key2 != NO_KEY)
  {
    while (key2 == NO_KEY)
    {
      key2 = keypad.getKey();
    }
    if (key2 != NO_KEY)
    {
      lcd.clear();
      lcd.setCursor(0,0);
      lcd.print("Enter Code: ");
      while (currentLength < 4){
        lcd.setCursor(currentLength + 6, 1);
        lcd.cursor();
        char key2 = keypad.getKey();
        if (key2 != NO_KEY)
        {
          lcd.print(key2);
          entered[currentLength] = key2;
          currentLength++;
          delay(200);
          lcd.noCursor();
          lcd.setCursor(currentLength + 5, 1);
          lcd.print("*");
          lcd.setCursor(currentLength + 6, 1);
          lcd.cursor();
        }
      }
      if (currentLength == 4){
        if (entered[0] == password[0] && entered[1] == password[1] && entered[2] == password[2] && entered[3] == password[3]){
          lcd.noCursor();
          lcd.clear();
          lcd.home();
          lcd.print(" Defused ");
          currentLength = 0;
          delay(2500);
          lcd.setCursor(0,1);
          lcd.print("Reset the Bomb");
        }
        else
        {
          lcd.noCursor();
          lcd.clear();
          lcd.home();
          lcd.print(" Wrong ");
          lcd.setCursor(0,1);
          lcd.print(" Add - 1:30 ");
          if (Mcount < 14)
          {
            Mcount = Mcount + 1;
          }
          if (Scount < 59)
          {
            Scount = Scount + 30;
          }
          delay(1500);
          currentLength = 0;
        }
      }
    }
  }
}

void timer()
{
  if ( Mcount >= 15 ){
    while ( Mcount >= 15){
      lcd.noCursor();
      lcd.clear();
      lcd.home();
      lcd.print(" !BoOm! ");
      tone1.play(NOTE_A2, 200);
      digitalWrite(ledPin, HIGH); // sets the LED on
      tone1.play(NOTE_A2, 200);
      delay(10); // waits for a second
      digitalWrite(ledPin, LOW); // sets the LED offtone1.play(NOTE_A2, 200);
      delay(10); // waits for a seconddigitalWrite(ledPin2, HIGH); // sets the LED on
      tone1.play(NOTE_A2, 200);
      delay(10); // waits for a second
      digitalWrite(ledPin2, LOW); // sets the LED offtone1.play(NOTE_A2, 200);
      delay(10); // waits for a secondchar key4 = keypad.getKey();
      if (key4 != NO_KEY){
        while (key4 == NO_KEY){
          key4 = keypad.getKey();
        }
        if (key4 = '#'){
          lcd.clear();
          lcd.print("Reset the Bomb");
        }
      }
    }
    if ( Mcount == 60) // if Mcount is 60 do this operation
    {//delay (32); // good place to fine tune timing
      Mcount = 0; // reset McountHcount ++;
    }
    if (Hcount> 23)
    {
      Dcount++;
      Hcount = 0; // have to reset Hcount to "0" after 24hrs}

      lcd.setCursor (0,1); // sets cursor to 2nd linelcd.print ("Timer: ");
      lcd.print (Dcount);
      lcd.print (":");
      lcd.print (Hcount);
      lcd.print (":");
      lcd.print (Mcount);
      lcd.print (":");
      lcd.print (Scount);
      if (Scount >59) // if 60 do this operation{
        Mcount ++; // add 1 to McountScount = 0; // reset Scount
      //delay (58); // changes ms per min}
      if (Scount < 60) // do this oper. 59 times{
        unsigned long currentMillis = millis();//delay (988); // changing by one = 60 ms a min
      if(currentMillis - secMillis > interval){
        tone1.play(NOTE_G5, 200);
        secMillis = currentMillis;
        Scount ++; // add 1 to ScountdigitalWrite(ledPin2, HIGH); // sets the LED on
        delay(10); // waits for a seconddigitalWrite(ledPin2, LOW); // sets the LED off
        delay(10); // waits for a second}
      }
    }
  }
}

Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12631
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I grit my teeth every time I see code with the opening brace appended to the preceding line. Particularly when, as here, it's not done consistently.

One of the biggest problems novices face is understanding the control structure of there code and especially seeing where it is not what they intended. Putting each matching pair of { and } on separate lines indented by the same amount makes this much easier to check visually.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Global Moderator
UK
Offline Offline
Brattain Member
*****
Karma: 302
Posts: 26278
I don't think you connected the grounds, Dave.
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
I grit my teeth every time I see code with the opening brace appended to the preceding line.
K&R and Linux kernel standard, but whoever wrote that junk is no Linux system programmer.
Braces on the wrong line were the least of my worries.
Logged

"Pete, it's a fool looks for logic in the chambers of the human heart." Ulysses Everett McGill.
Do not send technical questions via personal messaging - they will be ignored.

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12631
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

K&R and Linux kernel standard

Yeah, but if you're programming on a VT100 then reducing the number of lines in your code is important. These days a line saved here or there is pretty irrelevant and the only justification I can see for that style is habit. Putting each { and } on a separate line and indented by the same amount roughly halves the amount of work needed to spot the matching pairs.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

Offline Offline
Edison Member
*
Karma: 19
Posts: 1041
Arduino rocks
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

K&R and Linux kernel standard

Yeah, but if you're programming on a VT100 then reducing the number of lines in your code is important. These days a line saved here or there is pretty irrelevant and the only justification I can see for that style is habit. Putting each { and } on a separate line and indented by the same amount roughly halves the amount of work needed to spot the matching pairs.

If you indent correctly, no work is needed to spot the matching pairs. Any good text editor should highlight matching parenheses/etc as well.
Logged

Anaheim CA.
Offline Offline
Faraday Member
**
Karma: 47
Posts: 2891
...
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

That, I think was one of my most important discoveries, that and placing the cursor at the point of the curly brace to find the matching one. Now If I could only find a translator for the cuneiform output of the compiler error messages... 

Bob
Logged

--> WA7EMS <--
“The solution of every problem is another problem.” -Johann Wolfgang von Goethe
I do answer technical questions PM'd to me with whatever is in my clipboard

Seattle, WA USA
Offline Offline
Brattain Member
*****
Karma: 613
Posts: 49270
Seattle, WA USA
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Any good text editor should highlight matching parenheses/etc as well.
That works OK if the matching brace/paren/square bracket is in the window. Vertical alignment works even when the curly brace is beyond the top or bottom edge of the screen.

And, of course, no text editor can highlight the braces on the paper that comes out of the printer, while vertical alignment still works.
Logged

UK
Offline Offline
Shannon Member
****
Karma: 223
Posts: 12631
-
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

If you indent correctly, no work is needed to spot the matching pairs.

If you assume that the indentation and the braces match each other, that's true. But in this case you're effectively ignoring the braces and relying on the indentation. And the visual check that you need to perform to verify that the braces and the indentation match is roughly twice as difficult since you have to scan up the page to find which line the brace is expected to be on, and then across to the far end of the line to confirm it's there. And then do the same thing with all the intervening blocks to confirm that the brace you're looking at really is the matching pair of the one you started from.

Relying on a smart code editor to find matching pairs for you is all very well, but only when you have that editor available. For example, most of the Arduino code I look at here, I look at online on a passive web page with no language support. Quite often it's so poorly laid out that I need to copy it out into an external editor to make any sense of it. In my day job I use a wide variety of editors in different environments and they don't all have support for bracket matching. Even when they do, it's a pain to have to do the mouse-move, click, see where the matching bracket was rather than just run your eye up the page to find it. It's better than nothing, but no substitute for getting the code layout right in the first place. There is a definite advantage to putting the matching pairs of braces on separate lines indented by the same amount. It makes it much easier to visual find and pair them up without requiring any tools support.
Logged

I only provide help via the forum - please do not contact me for private consultancy.

United Kingdom
Offline Offline
Tesla Member
***
Karma: 224
Posts: 6614
Hofstadter's Law: It always takes longer than you expect, even when you take into account Hofstadter's Law.
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

hi
first, sorry for my English.
I'm trying to mount a simulated bomb, when compiling I get the error "was not delcared key4 In This scope"
Code many times I've looked and can not find the problem.

There is a line:

Code:
delay(10);// waits for a secondchar key4 = keypad.getKey();

I think that line should be split like this:

Code:
delay(10);// waits for a second
char key4 = keypad.getKey();

However, there are lots of other lines that look as if they have been joined together by mistake.

btw the comment is wrong, delay(10) does not wait for a second.
« Last Edit: October 14, 2012, 01:04:14 pm by dc42 » Logged

Formal verification of safety-critical software, software development, and electronic design and prototyping. See http://www.eschertech.com. Please do not ask for unpaid help via PM, use the forum.

Pages: [1]   Go Up
Jump to: