Pages: 1 2 [3]   Go Down
Author Topic: Audomatic Garage Door Close  (Read 3455 times)
0 Members and 1 Guest are viewing this topic.
Offline Offline
Newbie
*
Karma: 0
Posts: 40
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

About the goto alternative, you need to pick a good working logic and then decide, such as:

in the while loop, if certain condition is met, call an override function, which returns to the loop and the code continue to loop

or if with a different logic, you may decide to end the loop and then call the override function.

In any case, since the override code is pretty independent from other code, it can stay together as a function you can call.

It's best if you start with a flow diagram to specify how the program will run, and then write the code according to the flow diagram.

Thanks, I'm working on this and the other errors that were pointed out and I'll post back when done.
Logged

Central MN, USA
Offline Offline
Tesla Member
***
Karma: 74
Posts: 7255
Phi_prompt, phi_interfaces, phi-2 shields, phi-panels
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just a reminder: a general block diagram is independent from the fact you are using a "computer" to implement it. If I want to stand outside your garage holding all wires, I should be able to use the block diagram to carry out your project too. Once you have a sketch, try to get more specific in your next block diagram and then plan on how to write code to have arduino do it, instead of me.
Logged


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

Ok, went back to the drawing board a bit. I got rid of the goto, replaced it with a function, and also fixed the issue with the way I was referencing the state of the PINs. Using the suggestions given as guidance I was able to set it up so that there is a beep every x seconds while the override is active.

I'd be interested to hear your comments. 

* v2.2.txt (10.43 KB - downloaded 24 times.)
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 498
Posts: 19064
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Does it work?

In general in cases like this:

Code:
if (DoorCloseWarn == true) {
    Warn(); // go to the Warn function

Booleans can only be true or false, so testing for "== true" is a bit redundant. How about:


Code:
if (DoorCloseWarn) {
    Warn(); // go to the Warn function
Logged


New Jersey
Offline Offline
Faraday Member
**
Karma: 70
Posts: 3727
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Shouldn't the Calibrate function be called from setup rather than loop? Clearly either will work, but why bother checking for it in loop when it's a startup activity only?
Logged

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

Does it work?

In general in cases like this:

Code:
if (DoorCloseWarn == true) {
    Warn(); // go to the Warn function

Booleans can only be true or false, so testing for "== true" is a bit redundant. How about:


Code:
if (DoorCloseWarn) {
    Warn(); // go to the Warn function

It does work... both my uncle (who I wrote it for) have tested it and it all seems to function correctly. Good point on the DoorCloseWarn == true.

Thanks,
 Adam
Logged

Global Moderator
Offline Offline
Brattain Member
*****
Karma: 498
Posts: 19064
Lua rocks!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Shouldn't the Calibrate function be called from setup rather than loop? Clearly either will work, but why bother checking for it in loop when it's a startup activity only?

I was thinking that, but it has to be called 40 times. A 'for' loop might look better though, called from setup.
Logged


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

Does it work?

In general in cases like this:

Code:
if (DoorCloseWarn == true) {
    Warn(); // go to the Warn function

Booleans can only be true or false, so testing for "== true" is a bit redundant. How about:


Code:
if (DoorCloseWarn) {
    Warn(); // go to the Warn function

It does work... both my uncle (who I wrote it for) have tested it and it all seems to function correctly. Good point on the DoorCloseWarn == true.

Thanks,
 Adam

True. Honestly, I hadn't considered moving it outside the loop because I was not aware of how to work things outside of the loop. I'll have to play with your suggestion - I guess the benefit is that it's one less thing that has to be checked in the loop.
Logged

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

Shouldn't the Calibrate function be called from setup rather than loop? Clearly either will work, but why bother checking for it in loop when it's a startup activity only?

I was thinking that, but it has to be called 40 times. A 'for' loop might look better though, called from setup.

Would it cause issues running through it 40 times in setup?
Logged

New Jersey
Offline Offline
Faraday Member
**
Karma: 70
Posts: 3727
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Would it cause issues running through it 40 times in setup?
No, it'll be do exactly the same as it was before, except it won't have to check to see whether to calibrate on every iteration of loop.

Come to that, the for loop should be in the calibrate routine itself, rather than calling it 40 times.
Logged

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

Ok, changed it so that the calibration runs in setup - this was easy per recommendations I just did:

Code:
for (PIRCalTime = 0; PIRCalTime < 40; PIRCalTime++) {
    Calibrate(); // run the Calibrate function
  }

I also cleaned up the redundant if == true statements as suggested.

I know I got off to a rough start but thanks for all of you for your help. I've learned a lot. Appreciate your time.

* v2.3.txt (10.43 KB - downloaded 25 times.)
Logged

Pages: 1 2 [3]   Go Up
Jump to: