hi buddies anyone here to clarify my doubt,
using the single push button , in aurdino
,if i pressed for one time it has to activate for 15min timer
,if i pressed for two time it has to activate for 30min timer
,if i pressed for three time it has to activate for 60min timer,,
here i'm using timer for to turn on or turn off the switch
if possibly yes,,kindly share aurdino or esp8266 code
Post your sketch, well formated, with comments and in so called code tags "</>" and a timing diagram to see how we can help.
Do you have LEDs to indicate what timer is running on the time trigger?
Have a nice day and enjoy programming in C++ and learning.
You must have a "timeout" for all button presses for knowing "is it one press or three?"
For example, if you press the button twice, but you only wanted to press the button once, how long must you wait for the code to forget that you have pressed the button twice? If you press the button one more time (to get "one button press"), and your "timeout" is too long, your code will think you want 60 minutes, and not 15 minutes.
Write your "pseudo-code" like this:
10 Prepare for button press, a timer, a timeout
20 Wait for a button press
30 If button is pressed AND the "timeout" has not finished, you have one more button press, GO TO 20
40 set the timer for the number of presses and GO TO 20
////////////////////////////////////////////////////
//here my doubt is if timer is started for SINGLE CLICK event if it runs for long time in Between i want to execute DOUBLE CLICK how to do that
#include "OneButton.h" //we need the OneButton library
OneButton button(A1, true); //attach a button on pin A1 to the library
void setup() {
pinMode(13, OUTPUT); // sets the digital pin as output
pinMode(12, OUTPUT); // sets the digital pin as output
pinMode(11, OUTPUT); // sets the digital pin as output
button.attachDoubleClick(doubleclick); // link the function to be called on a doubleclick event.
button.attachClick(singleclick); // link the function to be called on a singleclick event.
button.attachLongPressStop(longclick); // link the function to be called on a longpress event.
}
void loop() {
button.tick(); // check the status of the button
delay(10); // a short wait between checking the button
} // loop
void doubleclick() { // what happens when button is double-clicked
digitalWrite(11,HIGH); // light the green LED
delay(5000000); // wait one second
digitalWrite(11,LOW); // turn off green LED
}
void singleclick(){ // what happens when the button is clicked
digitalWrite(12,HIGH); // light the red LED
delay(10000000); // wait one second
digitalWrite(12,LOW); // turn off the gren led
}
void longclick(){ // what happens when buton is long-pressed
digitalWrite(13,HIGH); // light the blue LED
delay(10000000); // wait one second
digitalWrite(13,LOW); // turn off the blue LED
}
///////////////////////////
/here my doubt is if timer is started for SINGLE CLICK event if it runs for long time
in Between i want to execute DOUBLE CLICK how to do that
// Define the pins being used
int pin_LEDgreen = 10;
int pin_LEDyellow = 9;
int pin_LEDred = 8;
int pin_switch = 2;
// variables to hold the new and old switch states
boolean oldSwitchState = LOW;
boolean newSwitchState = LOW;
byte state = 0;
{
// has the button switch been closed?
if ( newSwitchState == HIGH )
{
// increase the value of state
state++;
if (state > 3) {
state = 0;
}
// turn all LEDs off. Doing it this way means we do not need to care about the individual LEDs
// simply turn them all off and then turn on the correct one.
digitalWrite(pin_LEDgreen, LOW);
digitalWrite(pin_LEDyellow, LOW);
digitalWrite(pin_LEDred, LOW);
// Turn on the next LED
// Because the value of state does not change while we are testing it we don't need to use else if
if (state == 1) {
digitalWrite(pin_LEDgreen, HIGH)
delay(100000000);
digitalWrite(pin_LEDgreen, LOW)
}
if (state == 2) {
digitalWrite(pin_LEDyellow, HIGH);
delay(200000000);
digitalWrite(pin_LEDyellow, LOW);
}
if (state == 3) {
digitalWrite(pin_LEDred, HIGH);
delay(300000000);
digitalWrite(pin_LEDred, LOW);
}
}
oldSwitchState = newSwitchState;
It's the same problem as having to execute or do anything at all during a delay. It's not possible. You need to completely change your program logic design to follow non-blocking cooperative multitasking.