Hello Hans,
I know you’re busy, and I don’t want to claim you.
But maybe you can help me out sometime.
I have now adapted the code to ESP32 and it does fine.
Now I would like the touch button instead of the button.
The ESP32 have that onboard, unfortunately I can’t do it.
Greetings from Stuttgart
So this code works fine! How to implement this in my Code below?
#define BUTTON_1 T7 // Gpio 17 = Touch7
#define LED1 4
int touch_value = 100;
void setup(){
Serial.begin(115200);
Serial.println("Touch Test");
pinMode(LED1, OUTPUT);
digitalWrite (LED1, LOW);
}
void loop(){
touch_value = touchRead(BUTTON_1);
Serial.println(touch_value);
if (touch_value < 60)
{
digitalWrite (LED1, HIGH);
}
else
{
digitalWrite (LED1, LOW);
}
delay(1000);
}
// Für ESP32 als Transmitter
#define FASTLED_INTERNAL
#include <SPI.h>
#include <WiFi.h> // The Basic Function Of The ESP NODEMCU
// Defining I/O Pins
#define LED1 4 // LED1
#define BUTTON_1 5 // Button 1
// WIFI Authentication Variables
char ssid[] = "MyWiFi"; // SSID of your home WiFi
char pass[] = "123456789"; // password of your home WiFi
// WIFI Module Mode & IP
IPAddress server(192,168,3,250); // the fix IP address of the server
WiFiClient client;
#include <FastLED.h>
// How many leds in your strip?
#define NUM_LEDS 16
#define blinkcount 5
#define DATA_PIN 2
int buttonState=0;
// Define the array of leds
CRGB leds[NUM_LEDS];
//====================================================================================
void setup() {
Serial.begin(115200); // only for debug
WiFi.begin(ssid, pass); // connects to the WiFi router
while (WiFi.status() != WL_CONNECTED) {
Serial.print(".");
delay(500);
}
Serial.println("Connected to wifi");
Serial.print("IP: "); Serial.println(WiFi.localIP());
Serial.print("SSID: "); Serial.println(WiFi.SSID());
pinMode(LED1, OUTPUT);
pinMode(BUTTON_1, INPUT_PULLUP); // ESP Pin: INPUT_PULLUP
digitalWrite(LED1, LOW);
// edit one of the following lines for your leds arrangement if needed.
FastLED.addLeds<WS2812B, DATA_PIN, GRB>(leds, NUM_LEDS);
pinMode(BUTTON_1, INPUT_PULLUP);
LEDS.setBrightness(60);
}
//====================================================================================
void loop() {
ContinuousConnection();
}
//====================================================================================
void ContinuousConnection(){
client.connect(server, 80); // Connection to the server
ReadButton(); // Read Button from Transmitter
}
//====================================================================================
void ReadButton() {
int reading = digitalRead(BUTTON_1);
if (reading == LOW)
{
client.print("I am Transmitter\r");
delay(200);
}else{
ClientContinue();
}
}
//====================================================================================
void ClientContinue(){
client.println("Transmitter"); // sends the message to the server
String answer = client.readStringUntil('\r'); // receives the answer from the sever
if (answer == "I am Receiver") { // compares if response of receiver is equal to 'SWITCH'
digitalWrite(LED1, !digitalRead(LED1)); // if it changes the status of the LED
Serial.println("Data Received: " + answer);
// received something! Call the LED function
doLEDEffect();
delay(200); // client will trigger the communication 200 milliseconds
}
}
// ======= LED ========================================================
void doLEDEffect() {
buttonState=digitalRead(BUTTON_1); // put your main code here, to run repeatedly:
if (buttonState == HIGH)
{
for(int blink=0; blink<blinkcount; blink++) {
for(int i=0; i<NUM_LEDS; i++) {
leds[i].setRGB(255,0,0);
FastLED.show();
delay(10);
}
delay(100);
// Cleanup swipe after swipe
//setAll(0,0,0);
for(int i=0; i<NUM_LEDS; i++) {
leds[i].setRGB(0,0,0);
FastLED.show();
delay(10);
}
delay(100);
}
setAll(0,0,0);
}
else {
setAll(0,0,0);
}
}
// Set all LEDs to a given color and apply it (visible)
void setAll(byte red, byte green, byte blue) {
for(int i = 0; i < NUM_LEDS; i++ ) {
leds[i].setRGB(red, green, blue);
}
FastLED.show();
}