blynkkk / blynk-library

Blynk library for IoT boards. Works with Arduino, ESP32, ESP8266, Raspberry Pi, Particle, ARM Mbed, etc.
https://blynk.io
MIT License
3.84k stars 1.39k forks source link

help with physical button on blynk #536

Closed pablitoserna closed 3 years ago

pablitoserna commented 3 years ago

Blynk library version: [1.0] IDE: [Arduino] IDE version: [1.83] Board type: [Esp32] Additional modules: [...]

I'm having trouble running this code in conjunction with a physical button on blynk, I've tried it in several ways, I'm about to give up, can anyone help me? follow code below

Note: sorry for the errors, I don't speak English and I used google translator to ask for help, thank you for your attention.

define pinSentido1MotorA 32

define pinSentido2MotorA 33

const int TCPORTA = T4; int BTP = 26; int fimdecursoF = 15; int fimdecursoA = 4; const int sensibilidade = 55; int touchValue;

void setup() {

Serial.begin(115200); pinMode(BTP, INPUT); pinMode(pinSentido1MotorA, OUTPUT); pinMode(pinSentido2MotorA, OUTPUT); pinMode(fimdecursoF, INPUT); pinMode(fimdecursoA, INPUT); digitalWrite(pinSentido1MotorA, HIGH); digitalWrite(pinSentido2MotorA, HIGH);

}
void loop() {

//recupera a distância atual lida pelo sensor touchValue = touchRead(TCPORTA); int aberta = digitalRead(fimdecursoA); int fechada = digitalRead(fimdecursoF); int botao = digitalRead(BTP); Serial.print("Bota :"); Serial.println(botao); Serial.println(touchValue); Serial.print("Fim de curso porta aberta: "); Serial.println(aberta); Serial.print("Fim de curso porta fechada: "); Serial.println(fechada); delay(250);

if ((digitalRead(BTP)== HIGH) && (touchValue < sensibilidade) && (fechada == LOW) && (aberta == HIGH)) { Serial.println("Abre a Porta"); digitalWrite(pinSentido1MotorA, LOW); digitalWrite(pinSentido2MotorA, HIGH); }

   else if ((digitalRead(BTP)== LOW) && (touchValue < sensibilidade) && (fechada == HIGH) && (aberta == LOW))
   {
   digitalWrite(pinSentido1MotorA, HIGH);
   digitalWrite(pinSentido2MotorA, HIGH);
   Serial.println("Porta Aberta");
   }

   else if ((digitalRead(BTP)== HIGH) && (touchValue < sensibilidade) && (aberta == LOW) && (fechada == HIGH))
   {
   Serial.println("Fecha a Porta");
   digitalWrite(pinSentido1MotorA, HIGH);
   digitalWrite(pinSentido2MotorA,LOW);
   }

   else if ((digitalRead(BTP)== LOW) && (touchValue < sensibilidade) && (fechada == LOW) && (aberta == HIGH))
   {
   digitalWrite(pinSentido1MotorA, HIGH);
   digitalWrite(pinSentido2MotorA,HIGH);
   Serial.println("Porta Fechada");
   }

   else if ((digitalRead(BTP)== LOW) && (touchValue > sensibilidade) && (fechada == HIGH) && (aberta == HIGH))
   {
   Serial.println("Volta a Porta");
   digitalWrite(pinSentido1MotorA, HIGH);
   digitalWrite(pinSentido2MotorA, HIGH);
   delay(2000);
   digitalWrite(pinSentido1MotorA, HIGH);
   digitalWrite(pinSentido2MotorA, LOW);
   }

   else if((digitalRead(BTP)== LOW) && (touchValue > sensibilidade) && (fechada == HIGH) && (aberta == LOW))
   {
   digitalWrite(pinSentido1MotorA, HIGH);
   digitalWrite(pinSentido2MotorA, HIGH);
   Serial.println("Porta aberta por segurança");
   }

}

vshymanskyy commented 3 years ago

Please search for relevant questions (or ask your own) on our community forum: https://community.blynk.cc/