sorry about beginner question. May I know why is this code compiling, loading but not blinking ?
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // on the led
for (int i = 0; i< 2000 ; i+1) {
asm(""); // do nothing // do nothing for 2 seconds
digitalWrite(13, LOW); // off the led
} }
Because this is NOT the time you wait…and the for loop is still badly written. The increment part needs to be i++ or i=i+1
Also you don’t wait after setting the pin high so it will spend its time being off except for a few microseconds
Try
void myCrappyDelay(unsigned long loopCount) {
for (unsigned long i = 0; i < loopCount ; i++) asm(""); // do nothing
}
void setup() {
pinMode(13, OUTPUT);
}
void loop() {
digitalWrite(13, HIGH); // on the led
myCrappyDelay(2000000);
digitalWrite(13, LOW); // off the led
myCrappyDelay(3000000);
}
What if an interrupt happens when your do nothing loop is running? It would extend the completion time. 'delay()' is immune to that, because it uses a hardware timer.