Good night friends
i’m setting up another project, now with arduino uno.
I already got a part of what I wanted, a slider for a led strip and a blynk button to turn off.
Now comes the part I can’t get:
A physical button to turn on the same led strip, but a button that lasts for about 30 seconds.
For example, I open the door of the house and this light turns on for 30 seconds and then goes out.
This is the code I already use:
#define BLYNK_PRINT Serial
#include <SPI.h>
#include <Ethernet.h>
#include <BlynkSimpleEthernet.h>
char auth[] = "xxxxxx";
#define mosfetPin 6
#define botao 4
BlynkTimer timer;
//int t1;
// Toggle LED
void ledBlynk()
{
digitalWrite(mosfetPin, !digitalRead(mosfetPin));
}
BLYNK_WRITE(V0) {
//Blynk.syncVirtual(V1);
int value = param.asInt();
analogWrite(mosfetPin, value);
if (value == 0) {
Blynk.virtualWrite(V1,0);
Blynk.setProperty(V1,"offLabel","OFF");
}else {
Blynk.virtualWrite(V1,1);
Blynk.setProperty(V1,"onLabel","ON");
}
}
// BUTTON
BLYNK_WRITE(V1) {
int value = param.asInt();
digitalWrite(mosfetPin,value);
if (value==0) {
// change button to off
Blynk.virtualWrite(V0,0);
}else{
// change button to on
Blynk.virtualWrite(V0,255);
}
}
void setup()
{
// Debug console
Serial.begin(9600);
Blynk.begin(auth);
// Configure LED and timer
pinMode(mosfetPin, OUTPUT);
pinMode(botao, INPUT);
// t1 = timer.setInterval(500L, ledBlynk);
// timer.disable(t1);
}
void loop()
{
Blynk.run();
timer.run();
}