Hi Robiv8
It's OK to ask
Well, I'd use the same approach we used before.
Determine in the sketch what the "working parts" are and transplant them to the other sketch.
So the key elements of the 1st sketch are:
Header:
(i'm a little confused about the first define though ... should this be "T7" or "17"?).
This part we will need to add to the top of the sketch in which we combine both sketches (taking the 2nd sketch as a base).
#define BUTTON_1 T7 // Gpio 17 = Touch7
#define LED1 4
int touch_value = 100;
Setup:
This only sets the LED, so I'm not sure if we still will need this:
pinMode(LED1, OUTPUT);
digitalWrite (LED1, LOW);
Loop:
We transplant that to your ReadButton function:
touch_value = touchRead(BUTTON_1);
Serial.println(touch_value);
if (touch_value < 60)
{
digitalWrite (LED1, HIGH);
}
else
{
digitalWrite (LED1, LOW);
}
Your ReadButton function could become something like this depending on how this should work; touching would trigger the LED effect.
But, and this is more complex, does the release of the touch button also stop the LED effect?
void ReadButton() {
touch_value = touchRead(BUTTON_1);
Serial.println(touch_value);
if (touch_value < 60)
{
client.print("I am Transmitter\r"); // assuming te touch_value<60 = touch button
delay(200);
}
// else // dropped the release the button for now
// {
// digitalWrite (LED1, LOW);
// }
}
If the effect has to stop when releasing the touch button, then you'll need to create 2 "command".
For example, send "Effect ON" when pressed, and "Effect OFF" when released.
In your received sketch you'll need to handle the received messages accordingly.
The issue you'll run into is this: When the LED effect is running, the 2nd ESP8266 is "busy" and will not (yet) read the "Effect OFF" command.
A way to try to catch this would be by creating a function that checks if a command came in.
Before going that direction I'd clean up the code of both transmitter and receiver sketch first.
reading the code, and seeing the text "I am Transmitter" or "I am Receiver" confuse me each time hahah.
Also not that this part of the code:
void loop() {
ContinuousConnection();
}
//====================================================================================
void ContinuousConnection(){
client.connect(server, 80); // Connection to the server
ReadButton(); // Read Button from Transmitter
}
doesn't really contribute. Short, cleaner and better would be:
void loop() {
client.connect(server, 80); // Connection to the server
ReadButton(); // Read Button from Transmitter
}
and drop the "ContinuousConnection" function - it is not being used anywhere else.