Pages: [1] 2   Go Down
Author Topic: returning from a statement  (Read 844 times)
0 Members and 1 Guest are viewing this topic.
Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I have got confused about where the sketch will return after calling a statement.

I have looked at the IfStatement section of the tutorial ( which incidentaly shows an LED connected to a pin with no resistor !  a 220 ohm res is mentioned in the parts list, but not on the Fritzing or the schematic )

I have made a sort of flowchart for a sketch I must write,   simplified, I have  if ( vtSense == HIGH ) { update () ;}
some parts of the update statement refer a variable " timing "  which is HIGH or LOW.

At the end of update () the sketch must continue to another statement called  "checkclock ()"

If vtSense is LOW however , from the if function,  I want it to set  timing = LOW , and then carry on to the checkclock() statement.

I always assumed the "if" function would return to where it was called, which in this case would then set the timing LOW, which I dont want.

If I use an "else "  for setting the timing LOW,  would it skip this ?,  it seems to be from this part of the tutorial which is talking about multiple tests

Quote
else can proceed another if test, so that multiple, mutually exclusive tests can be run at the same time.
Each test will proceed to the next one until a true test is encountered. When a true test is found, its associated block of code is run, and the program then skips to the line following the entire if/else construction.
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

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

A more complete example that demonstrates this problem would help.

Quote
returning from a statement

You mean, a function?
Logged


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

Quote
Code:
if ( vtSense == HIGH ) { update () ;}

some parts of the update statement refer a variable " timing "  which is HIGH or LOW.

At the end of update () the sketch must continue to another statement called  "checkclock ()"

Not in the code you posted it doesn't.
Logged


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

Quote
Posts: 999

Almost there!
Logged


East Anglia (UK)
Offline Offline
Faraday Member
**
Karma: 114
Posts: 4261
May all of your blinks be without delay()
View Profile
 Bigger Bigger  Smaller Smaller  Reset Reset

What Nick is getting at is that it is necessary to see all of your code in order to provide advice.
Logged

Please do not send me PMs asking for help.  Post in the forum then everyone will benefit from seeing the questions and answers.

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

I know  999 , I thought I would go out on a bang with a confused posting!  

I have been up since 3am trying to get the rough idea of this sketch together, and I get my functions and statements mixed up at the best of times :-(

I havnt actually written anything yet, apart from some of the subroutines   er I mean functions :-)

Basically does an if statement return to the part of the sketch immediately after the statement ( in other words to the first line that would have been if the statement was false ) ?

and if I use "else"  ( and the statement is true ) would it rather return to the first line after what it would have run had the statement been false ?

If this doesnt make sense I will write a bit of sample code to try / post.
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

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

An "if" doesn't really go anywhere, so seeing your code will help answer your question.
Logged


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

Quote
Posts: 1000

Congrats on becoming an Edison member!
Logged


Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks Nick,    Edison is very confusing with simple code !

I will post somethng when I have got it written ( if I am still confused )  perhaps half an hour on the stoep on my hammock will help :-)
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

So now I start to write a test using blink in the background to make sure its running :-

Code:

// int timing = LOW;
//int vtState = LOW;
int number  ;

void setup() {                
  number = 2;
  pinMode(13, OUTPUT);  
 Serial.begin(9600);  
  Serial.print(' number =  '); Serial.println(number);
}

void loop() {
  digitalWrite(13, HIGH);   // set the LED on
  Serial.print(' number =  '); Serial.println(number);
  delay(1000);              // wait for a second
  digitalWrite(13, LOW);    // set the LED off
  delay(1000);              // wait for a second
}

and when I run even this, the serial out on the monitor ( at 9600 ) just shows 82242 every second,  with no text , even in setup.

The LED is blinking OK so the chip is OK.

Edison looks like its going to be interesting ............

« Last Edit: January 30, 2013, 04:38:35 am by Boffin1 » Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

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

Code:
Serial.print(' number =  ');
Double quotes for strings.

Quote
82242
The last 2 is the one you printed, and 8224 = 0x2020 = two spaces.
« Last Edit: January 30, 2013, 04:46:20 am by AWOL » 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.

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

Thanks AWOL,  at least I had the grounds connected :-)

I have never typed that before ,   I must get some sleep.

Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

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

Ease up on the Stellenbosch   smiley-wink
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.

Cape Town South Africa
Offline Offline
Edison Member
*
Karma: 19
Posts: 1217
A newbie with loads of posts, and still so much to learn !
View Profile
WWW
 Bigger Bigger  Smaller Smaller  Reset Reset

The suns not Gone down yet ! 
Logged

With my mobile phone I can call people and talk to them -  how smart can you get ?

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

That glass in your hand looks pretty well-lit!
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.

Pages: [1] 2   Go Up
Jump to: