What am I doing wrong.. Seems that I can't put a loop in server.on( { }
How am I supposed to do it, if I wanna do it the right way?
server.on("/blink", [](){
// the loop function runs over and over again forever
void loop() {
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
});
server.on("/blink", []() {
// the loop function runs over and over again forever
loop();
});
void loop() {
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
// the loop function runs over and over again forever
loop();
});
void loop() {
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
use an anonymous function to call unique function... why?
the problem in the code is (as Paul pointed out) is the issue with declaring a (very poorly named) function within the lambda. a looping construct can certainly be put into the lambda.
the OP may not literally want "the loop function runs over and over again forever" it looks like a cut and paste issue to me.
server.on("/blink", []() {
// the loop function runs over and over again forever
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
});
server.on("/blink", []() {
// the loop function runs over and over again forever
while (true) {
digitalWrite(ledPin, HIGH); // turn the LED on (HIGH is the voltage level)
delay(1000); // wait for a second
digitalWrite(ledPin, LOW); // turn the LED off by making the voltage LOW
delay(1000); // wait for a second
}
});