Abdellazizhammami / arduino

Automatically exported from code.google.com/p/arduino
Other
0 stars 0 forks source link

Assigning values in Global scope is not working #778

Open GoogleCodeExporter opened 8 years ago

GoogleCodeExporter commented 8 years ago
What steps will reproduce the problem?

The variable declared in the Global scope is not functional inside the loop() 
function. e.g.

int x = 1;
int y = x;

loop(){
  //y is not == 1
}

Once I put the line "Serial.begin(9600)" inside the setup() function, the code 
just works fine. e.g.

int x = 1;
int y = x;

setup(){
  Serial.begin(9600);
}
loop(){
  //y is now == 1
}

What is the expected output? What do you see instead?

I have create a video to demonstrate the issue:
http://www.youtube.com/watch?v=VKjBnSz1ZZs

We also has a full discussion in the Arduino forum:
http://arduino.cc/forum/index.php/topic,85745.0.html

What version of the Arduino software are you using? 
Arduino IDE 1.0

On what operating system?  
Mac OSX Lion

Which Arduino board are you using?
Arduino UNO(328)

Please provide any additional information below.
Full source code attached.

Thank you!

Original issue reported on code.google.com by fran...@franfran.com on 7 Jan 2012 at 6:08

Attachments:

GoogleCodeExporter commented 8 years ago
Just a quick update to save you sometime.  The Arduino forum members found out 
that the problem was caused by the 0xFF bytes issue in the hex file.

So if assigning values in the Global scope, the program won't work:

int dimUp = 1;
int dimDown = -1;

Instead, we now have to put them in the setup() function:

int dimUp;
int dimDown;

setup(){
  dimUp = 1;
  dimDown = -1;
}

Hope it helps, thx.

Original comment by fran...@franfran.com on 7 Jan 2012 at 3:38