I’m a newbie in Arduino. I’ve got my SIK 3.1 just yesterday and was playing with it when I got a critical error on my Macbook Pro and system just rebooted.
How that happened? During compiling code in Arduino (circuit 4 of SIK).
I changed “-” to “+” as shown in the code below and pressed compilation button.
for(index = 7; index >= 0; index+-)
Question: Why my laptop rebooted? Any reasonable explanation?
void oneAfterAnotherLoop()
{
int index;
int delayTime = 100; // milliseconds to pause between LEDs
// make this smaller for faster switching
// Turn all the LEDs on:
// This for() loop will step index from 0 to 7
// (putting "++" after a variable means add one to it)
// and will then use digitalWrite() to turn that LED on.
for(index = 0; index <= 7; index++)
{
digitalWrite(ledPins[index], HIGH);
delay(delayTime);
}
// Turn all the LEDs off:
// This for() loop will step index from 7 to 0
// (putting "--" after a variable means subtract one from it)
// and will then use digitalWrite() to turn that LED off.
for(index = 7; index >= 0; index+-)
{
digitalWrite(ledPins[index], LOW);
delay(delayTime);
}
}
I don’t know if that would crash your computer, but I know why that wouldn’t work. That last part is the increment or decrement counter. It tells index to increase or decrease with each iteration of the loop. That line sets index to 7 at the beginning, tests the condition (is index greater than or equal to zero), runs the loop, changes the value of index, then tests the condition again. Since “±” isn’t a valid thing to have in a For loop, the Arduino IDE threw an error while compiling. For more information, look at the Arduino explanation of For loops http://arduino.cc/en/Reference/for
I tried the Circuit 4 code on my computer with your change. While I got an error, nothing crashed. Every setup is different, though, so it is possible the compiler’s error caused other problems for your Macbook.
TS-Liz:
I don’t know if that would crash your computer, but I know why that wouldn’t work. That last part is the increment or decrement counter. It tells index to increase or decrease with each iteration of the loop. That line sets index to 7 at the beginning, tests the condition (is index greater than or equal to zero), runs the loop, changes the value of index, then tests the condition again. Since “±” isn’t a valid thing to have in a For loop, the Arduino IDE threw an error while compiling. For more information, look at the Arduino explanation of For loops http://arduino.cc/en/Reference/for
I tried the Circuit 4 code on my computer with your change. While I got an error, nothing crashed. Every setup is different, though, so it is possible the compiler’s error caused other problems for your Macbook.
Keep experimenting! That’s how you learn
thanks for the detailed explanation. I also understand that logically the function “±” doesn’t make any sense, I was just experimenting to see what will happen. Unfortunately that caused crash of whole system
Anyway, I will continue to experiment. I like to explore new stuff. Hope, I will not fry my laptop. :mrgreen: