controlling "operations"
Posted: Mon Jan 02, 2017 11:51 am
Hi all,
After working with the 8266 for a year or so(off and on), I still consider myself a newbie because there are quite a few "holes" in my understanding. For one thing, way back in my early days(before the term "PC" was coined), we worked with routines, subroutines calls returns, jumps, etc. The way I understand the philosophy used by Arduino's C we talk about functions (not sure that's totally correct). That being said, void setup() would be a function, as is void loop(). I get that (I think ).
One of the things I find confusing is that in examples of servers being presented much work is done in the setup function as such:
and the loop (being only one line of code) I find quite confusing. My brain tells me is should be the other way around
I have successfully followed others provided examples to turn on/off a gpio pin for several different projects. And have been vasilating between the Arduino IDE and Nodemcu platforms. Rumor now has it that Nodemcu may not see much more development so I am leaning more toward the Arduino IDE. I want learn to do more than just turn gpio's on and off, and move on to being able to control other "operations" (so as not to use the term subroutine) within the sketch. For example from a browser, turn on a gpio to "fade" mode in a continuous manor until a request to turn it off is received, or change viewings of various sensors. I'm lost at tying these two simple things together, I think because of my confusion explained above . Finding tutorials to aid in educating myself becomes frustrating as well with the speed of changes coming forth. So the question is: Is there a repository of examples WITH explanations above and beyond "do this", more "like do this because.." I do realize that my knowledge of "today's" languages (like C and scripting in general) is in it's infancy so I think that explanations would be most helpful. Any steering is greatly appreciated.
After working with the 8266 for a year or so(off and on), I still consider myself a newbie because there are quite a few "holes" in my understanding. For one thing, way back in my early days(before the term "PC" was coined), we worked with routines, subroutines calls returns, jumps, etc. The way I understand the philosophy used by Arduino's C we talk about functions (not sure that's totally correct). That being said, void setup() would be a function, as is void loop(). I get that (I think ).
One of the things I find confusing is that in examples of servers being presented much work is done in the setup function as such:
Code: Select all
void setup(void){
webPage += "<h1>ESP8266 Web Server</h1><p>Socket #1 <a href=\"socket1On\"><button>ON</button></a> <a href=\"socket1Off\"><button>OFF</button></a></p>";
webPage += "<p>Socket #2 <a href=\"socket2On\"><button>ON</button></a> <a href=\"socket2Off\"><button>OFF</button></a></p>";
// preparing GPIOs
pinMode(gpio4_pin, OUTPUT);
digitalWrite(gpio4_pin, LOW);
pinMode(gpio5_pin, OUTPUT);
digitalWrite(gpio5_pin, LOW);
delay(1000);
Serial.begin(115200);
WiFi.begin(ssid, password);
Serial.println("");
// Wait for connection
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.print("Connected to ");
Serial.println(ssid);
Serial.print("IP address: ");
Serial.println(WiFi.localIP());
if (mdns.begin("esp8266", WiFi.localIP())) {
Serial.println("MDNS responder started");
}
server.on("/", [](){
server.send(200, "text/html", webPage);
});
server.on("/socket1On", [](){
server.send(200, "text/html", webPage);
digitalWrite(gpio4_pin, HIGH);
delay(1000);
});
server.on("/socket1Off", [](){
server.send(200, "text/html", webPage);
digitalWrite(gpio4_pin, LOW);
delay(1000);
});
server.on("/socket2On", [](){
server.send(200, "text/html", webPage);
digitalWrite(gpio5_pin, HIGH);
delay(1000);
});
server.on("/socket2Off", [](){
server.send(200, "text/html", webPage);
digitalWrite(gpio5_pin, LOW);
delay(1000);
});
server.begin();
Serial.println("HTTP server started");
}
void loop(void){
server.handleClient();
}
and the loop (being only one line of code) I find quite confusing. My brain tells me is should be the other way around
I have successfully followed others provided examples to turn on/off a gpio pin for several different projects. And have been vasilating between the Arduino IDE and Nodemcu platforms. Rumor now has it that Nodemcu may not see much more development so I am leaning more toward the Arduino IDE. I want learn to do more than just turn gpio's on and off, and move on to being able to control other "operations" (so as not to use the term subroutine) within the sketch. For example from a browser, turn on a gpio to "fade" mode in a continuous manor until a request to turn it off is received, or change viewings of various sensors. I'm lost at tying these two simple things together, I think because of my confusion explained above . Finding tutorials to aid in educating myself becomes frustrating as well with the speed of changes coming forth. So the question is: Is there a repository of examples WITH explanations above and beyond "do this", more "like do this because.." I do realize that my knowledge of "today's" languages (like C and scripting in general) is in it's infancy so I think that explanations would be most helpful. Any steering is greatly appreciated.