Pages: 1 [2] 3 4 ... 10   Go Down
Author Topic: Structure of code. Need help.  (Read 7309 times)
0 Members and 1 Guest are viewing this topic.
Oz
Offline Offline
God Member
*****
Karma: 5
Posts: 804
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Sorry.

I missed your modification.

I'm not upset, but it isn't my code.  All this is cut/paste from the existing code which I am trying to get my head around.

(I am looking at it ITMT, but shall ask in case I can't resolve it myself)
Next silly question:
How do I access this variable?
Ok, it is returned, but then I guess I need to put this in the line when calling:

(I know I am using the same name, but at this time of day, my brain can't make better names)
(I accept that each are unique and each name is "local" to where it is.)

active_alarm =

Or is it just active_alarm

And what is the name of the function?

There are too many of these {  }  around and I can't keep a correct track of them.

And how "global" is this new name?

« Last Edit: June 09, 2012, 05:40:38 am by lost_and_confused » Logged

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

You name the variable whatever you want.  The current "active_alarm" variable is "local" to the function - that is, it is only available within the function itself.  The value that is stored in that function is "return"ed from the function for you to store in your own variable.

At the moment all we have seen is a class.  To know what you are doing with that class we will have to see the rest of your code.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Oz
Offline Offline
God Member
*****
Karma: 5
Posts: 804
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Would someone like to give me their e-mail address and I can post it to you?

In ZIP format.
Logged

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Just attach it to a forum post.  Select "|> Additional Options..." at the bottom of the post box.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Oz
Offline Offline
God Member
*****
Karma: 5
Posts: 804
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Oops.

Sorry.

 smiley-kiss

* V3.zip (13.9 KB - downloaded 5 times.)
Logged

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Code:
void top_menu_function_1() //This runs the clock
{
  lcd.clear();
  center_text("Anykey for menu");
  wait_on_escape(1000);
  lcd.clear();
  int temp1;
  while (1)
  {
    clock1.run();
    if (!clock1.alarm_is_on)
    {
      temp1=wait_on_escape(1000);
      switch (temp1)
      {
        case 0:
        break;
 
        default:
        return;
        break;
      }
    }
  }
}

This is where you are actually using the run() function.  You have created a clock1 object, and are calling the run function within that.

To get at the returned value (of my modified run() function) you would have to assign it to a variable of your choosing:

Code:
void top_menu_function_1() //This runs the clock
{
  byte activeAlarm; /* */
  lcd.clear();
  center_text("Anykey for menu");
  wait_on_escape(1000);
  lcd.clear();
  int temp1;
  while (1)
  {
    activeAlarm = clock1.run();  /* */
    if(activeAlarm > 0)              /* */
    {              /* */
       // do something with the activeAlarm variable - it contains a number from 1 to 4.
    }             /* */

    if (!clock1.alarm_is_on)
    {
      temp1=wait_on_escape(1000);
      switch (temp1)
      {
        case 0:
        break;
 
        default:
        return;
        break;
      }
    }
  }
}


Or something similar.
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Oz
Offline Offline
God Member
*****
Karma: 5
Posts: 804
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Overview of what I want to do - ultimately

I have a 20 x 4 display on my setup.

There are 4 alarms.
I want 4 "icons" (bell symbols) to indicate an alarm is SET.
These are on the last column of all 4 rows.

When an alarm is active, a bell symbol is put at a position along the top line depending on which alarm it is.  Beside that a space and then 2 digits showing the remaining time for that alarm's time.

I have 2 pins (16 and 17) to control outside things.
3 would be better, but....
I also would like to define which alarm does what with which alarm output.
So alarm 1 may turn on both, alarm 2 may only do 16, alarm 3 does 16 and alarm 4 does only 17.
EXAMPLES.
Also alarm run times for each alarm may be better.
You can see I added an extra setup menu item for "Alarm run time" but that applies to all alarms.
Work in progress.

Also, I am wanting to add "extra" buttons/keyboard.
The pins on the shield are kind of inside the box, so I can't use them.
On the keyboard I need (so far) some other functions:
One button when pressed will activate an output for 'x' minutes.
Another button will activate another output for 'y' minutes and if pressed again, will turn the output off.


Now, if you have read this far, I am thankful.
But please don't do the code for me.  I want to learn what to do myself.  What I need is help getting my head around the code.

Logged

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

I know this will sound trite, but you've really bitten off more than you can chew.
You've learnt the equivalent of "un chat, un chien", and now you're trying to read "A la recherche du temps perdus".

Slow down, and get a solid foundation by learning the basics.
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.

Oz
Offline Offline
God Member
*****
Karma: 5
Posts: 804
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

AWOL,

Yeah, I know.

Alas this is "an important" job and though some of those things are not essential, they are in the queue of things to do.

I have moved up from discreet electronics and into computer stuff, so I am not wanting to mess about too much but get really into it.

Logged

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Quote
Alas this is "an important" job and though some of those things are not essential, they are in the queue of things to do.

If a job is worth doing, it's worth paying me to do it for you smiley-razz  smiley-lol
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Oz
Offline Offline
God Member
*****
Karma: 5
Posts: 804
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

I'm working on it, but I got this error:

Example_menu:154: error: 'activeAlarm' was not declared in this scope

I put the return line in the other code (ok, forgot the first time) but am still getting this error.
I'm guessing I shall have to set it up or something.
Logged

Oz
Offline Offline
God Member
*****
Karma: 5
Posts: 804
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Well, it is important as in it is my alarm clock.

The one I had worked quite well for 25 years but died.

I want one which can do the same sort of thing, but the old version was not that good and was probably not as good as this one will become.

As I want to get into the Arduino stuff, this seems like a good place to start, as there is importance and so I shall give it time and not just lose interest in it after a while.

Logged

UK
Offline Offline
Faraday Member
**
Karma: 100
Posts: 4153
Where is your SSCCE?!?!
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Did you see the line nearer the top:

Code:
  byte activeAlarm; /* */

?
Logged

Get 10% off all 4D Systems TFT screens this month: use discount code MAJENKO10

Oz
Offline Offline
God Member
*****
Karma: 5
Posts: 804
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Apologies

 smiley-red
Logged

Oz
Offline Offline
God Member
*****
Karma: 5
Posts: 804
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

Ok it works.  Kinda.

I am not sure how to test it, but it complies with what you gave me.

In the "alarm_clock" file, line 171 (thanks again for pointing out the line numbers)

That is where this "activeAlarm" variable comes into use/is needed.

I am going to try to work out how to "export it" from where it is and make it usable in the other routine.

What I shall try is to cut/past that small part of the routine into that area and use the value there.
Logged

Pages: 1 [2] 3 4 ... 10   Go Up
Jump to: