Put 2 codes together! (School project)

I use an Nodemcu ESP8266 1.0

Hi.

I have a school project, and I really need help to put 2 off my codes together. Both of the codes is working fine, but when i try to put them in a same sketch it failed.

I have 1 code with my clapping sensor who should turn on a socket, and the other code is a WIFI controller should turning on/off the same socket.

Dettafunka.ino (1.19 KB)

test_32479234.ino (1.76 KB)

So, you have two programs that work, so you posted them, and you have some attempt to combine them that is somehow not doing what you want, that you need help with, but you didn't post that code or explain what the issues are. That's not how to move forward.

Hi and thanks for answearing. I posted both codes as two attachments. I am new to this forum, so im sorry if i did something wrong.
Yes i have trouble to combine them. Every thing is working fine untill i should put my void loop from the wifi controller.

Look at the code i put in as a attachment under, on this cocde i have tried to combind them, but Line 1-10 is my void loop from the wifi controller, but i dont know where i can put it so it works...

arduinohelp.ino (2.72 KB)

Some1 said i need to get 2 loops, one for the clapping sensor and one for the wifi? but idk how i do that, and i have search on google but cant find it...

You don't "put the void loop" from one sketch into the other.

You might put some, or all, of the code from the loop() function in one sketch into the loop() function in another sketch.

Yes i have tried that. But i think this while loop from the wifi does that the clap would not be detected if i put it in the same loop as clapper loop..

WiFiClient client = server.available();
if (!client) {
return;
}
while (!client.available()) {
delay(1);
}
rest.handle(client);

kjetilmarstein:
Yes i have tried that. But i think this while loop from the wifi does that the clap would not be detected if i put it in the same loop as clapper loop..

WiFiClient client = server.available();
if (!client) {
return;
}
while (!client.available()) {
delay(1);
}
rest.handle(client);

While you are handling a client request, you won't be listening to clapping. Therefore, you need to make your client handling function as fast as possible, so that you don't miss too many claps.

It would probably be better to use two Arduinos - one as the server and one as the clapper. The clapper Arduino can tell the server Arduino that the lights should be off or on in a variety of ways.

Ok. Thank u! Mabye i should try that. But this is my first project with this esp8266 wifi thing, so im not sure how to do that the arduino is telling the server when the led is on/of? Do u have a code for that?

Maybe i can use the output from server(arduino) as an input to my arduino(clapper)?

Suppose that the clapper Arduino needed to turn an LED on when it detected a clap. Could you do that?

Could you connect a wire from the pin that the LED is/would connected to some pin on the other Arduino (with the ESP device on it), along with ground, of course?

Could you, on the server Arduino, read the state of that pin?

Maybe i can use the output from server(arduino) as an input to my arduino(clapper)?

Maybe, but it seems more likely that you want to use the output from the clapper as an input to the server.

in your arduinohelp.ino call the serverLoop a the end of loop()