Interesting. I would expect the compiler to optimize those statements out of existence, since assigning led a value and incrementing it never does anything useful.
No because there is nothing wrong with that code you posted, if you uncomment those two lines then there will be no change in what the sketch does because the variable led is not used in any other part of the sketch. Are you sure you posted the right thing?
I am sure, I posted the right thing. I tryit more times and did more variants of it, this one is the simplest, which does something visible.
I also tried avr-objdump -DCfhlSwz Ugh.cpp.elf >Ugh.cpp.asm and found, that there is difference, as the working version have .data segment and does incrementing the led
int led = 7; // This assigns the value 7 to a variable called led
void setup() {
led++; // This increments led, making it have a value of 8
for ( int i=7;i<14;i++){ // these two lines set pins 7 - 13 to OUTPUT
pinMode(i, OUTPUT);
}
}
void loop() {
for ( int i=7;i<14;i++){
digitalWrite(i, HIGH); // This line sets pins 7 - 13 HIGH, 1 pin per loop
delay(100);
digitalWrite(i, LOW); // This line sets pins 7 - 13 LOW, 1 pin per loop
delay(100);
}
} // and this line makes it go all around the loop, setting pins 7 - 13 HIGH/LOW in turn
You need to use the variable led in your digitalWrite(). Just because you called it led, doesn't make it automatically know what to do.
No, I am now far from home with netbook only. Iven in home I do not have any Windows, just couple of Gentoo machines, usually even without Xs or monitor attached (ssh only access)
int led = 7; // This assigns the value 7 to a variable called led
void setup() {
led++; // This increments led, making it have a value of 8
for ( int i=7;i<14;i++){ // these two lines set pins 7 - 13 to OUTPUT
pinMode(i, OUTPUT);
}
}
void loop() {
for ( int i=7;i<14;i++){
digitalWrite(i, HIGH); // This line sets pins 7 - 13 HIGH, 1 pin per loop
delay(100);
digitalWrite(i, LOW); // This line sets pins 7 - 13 LOW, 1 pin per loop
delay(100);
}
} // and this line makes it go all around the loop, setting pins 7 - 13 HIGH/LOW in turn
You need to use the variable **led** in your digitalWrite(). Just because you called it led, doesn't make it automatically know what to do.
I am using variable i in digitalWrite, which goes from 7 to 13 to make blik different diodes. Just namind the variable led does not mean I want it use for anything. This code works and makes running light over leds 7-13, regardles value of led variable.
The problem is, when I comment out the led variable (both declaration and incrementation) the sketch stops working and lights only led 7. And I do not understand why, because the variable led here is totally nonsencial (it is rest from Blik sketch and when i deleted it it istopped working. When I returned it, it worked again.)
The problem is, when I comment out the led variable (both declaration and incrementation) the sketch stops working and lights only led 7.
Hey guys, this is beginning to ring bells from quite a few years ago. We had something like this then. Trouble is I can't remember the details but I think it was something to do with the compiler.
Also - if i comment out both delay(), then it runs ok even with led commented out (only all leds are blinking so fast, that they look just dimmed)
also if i use my own delay, it works ok everytime
void delay2(int d) { //does some delay, do not care about correct timing
volatile int a; // do not want be optimized out by compiler
for (int i=0;i<d;i++) {
for (long unsigned l=0;l<0xFFF;l++) {
a=d; // do not want be optimized out by compiler
}
}
}
Another try - I installed git-version of Arduino (not suported by portage) and from it works. Still I do not understand, what happend and why (and I would like to understand it)
gilhad:
it compiles without problems, but once uploaded, it lights pin 7 and does nothing more
But if I uncomment the two lines with led, it uploads and start blinkind all pins 7-13.
If I comment out the led, it stuck again.
I used IDE 1.0.4 on Windows 7 Pro 64-bit to upload the code in the original post to a UNO R3, and pin 13 blinked briefly at a bit less than 1Hz. That's what I'd expect from that code. Then I tried again using IDE 1.5.2 - no problem there either. In other words, I couldn't reproduce the problem.
PeterH:
I used IDE 1.0.4 on Windows 7 Pro 64-bit to upload the code in the original post to a UNO R3, and pin 13 blinked briefly at a bit less than 1Hz. That's what I'd expect from that code. Then I tried again using IDE 1.5.2 - no problem there either. In other words, I couldn't reproduce the problem.
Has anyone else reproduced the problem?
I have not been able to reproduce the failure on IDE 1.5.4