I am working on arduino IDE and esp8266 nodemcu. As i am going through the IDE I saw that there is a structure of void loop() and void setup() and all examples in the internet included defining the pinModes within the void setup() block. I want to make a program where through mqtt or http the user will give input as to what type of device he/she wants to attach to the esp8266, so based on that i will have to set, INPUT/OUTPUT state on the following pins.
Now my initial idea was :
void setup()
{
connectwifi();
}
void loop()
{
call_some_function();
}
where call_some_function()
will recieve the requirements from user over http. For example he wants a light on pin3, so pinMode(pin3,OUTPUT);
now what I wanted is that,
call the method - call_some_function()
whenever the user needs to add an extra device to it, which means initally when we wanted to add 4 lights to esp8266, we will write
pinMode(pin1,OUTPUT);
pinMode(pin2,OUTPUT);
pinMode(pin3,OUTPUT);
pinMode(pin4,OUTPUT);
But now when I have a user defined input, my code will become something like this,
call_some_function()
{
pin=(user gave me the pin no);
state=(based on the device the server will send the state i.e IN/OUT);
pinMode(pin,state);
}
Now my question is , calling this function 4 times and writing pinMode()
function 4 times will result in same thing or separate?
Also is this doable, like can i write like this?
I will be calling this function from void loop()
instead if void setup()
, since I continuously listen for user input,
Cause I cannot find any other way of making user specific input