Page 1 of 1

2 Switch, 1 LED blink and light

Posted: 10 May 2020, 10:08
by druckgott
Hallo, I have two switches on GPIO2 (SW1) and GPIO14(SW2) and I have a LED on GPIO 13.

The two switches can never pushed parallel due to the hardware!

Now I want to have it like this.

If SW1 is pushed and SW2 is not pushed then the LED should be off
If SW1 is not pushed an SW2 is not pushed the LED should blink
If SW2 is pushed and SW1 not pused the LED sould light without blinking

This is my code, but it´s not working:
if SW1 is pushed and SW2 is off the led is off
if SW1 is off and SW2 is off the led is blinking
but if SW2 is pushed and SW1 is off the led is blinking some times or off

Code: Select all


On garage_close#Value=0 do
   //blink
   timerSet,1,1
 endon

On garage_close#Value=1 do
  //stop blinking
   timerSet,1,0
 endon


On garage_open#Value=0 do
 //switch off led and blink
  GPIO,13,0
   timerSet,1,1
 endon

//wenn geschlossen aus
On garage_open#Value=1 do
//switch off blink and light
   timerSet,1,0
     GPIO,13,1
 endon

 //create an actual warning signal, every time 
timer 1 expires:
 On Rules#Timer=1 do 
   //repeat after 2 seconds 
   timerSet,1,1
    //pulse some led on pin 4 shortly
   Pulse,13,1,200
 endon
 
I do not know why it´s not working.

Re: 2 Switch, 1 LED blink and light

Posted: 10 May 2020, 13:30
by Ath
Well, I just built your scenario, but I'm not sure you have stuff set up right:
- My led is on GPIO5, and it is active-low, not active-high as you seem to have (on high the GPIO doesn't deliver much current, though on low it can pull some current)
- My switches are set up as Normal Switch, with internal pull-up, and Inversed logic, shorting the GPIO to ground when closed. (IRL, you will need external pull-up resistors ~10k to avoid picking up spurious spikes)

My rules are now like this (I did remove the extra enter you had in one comment, I hope it is not in your actual code)

Code: Select all

On garage_close#Value=0 do
  //blink
  timerSet,1,1
endon

On garage_close#Value=1 do
  // Light off
  GPIO,13,1
  //stop blinking
  timerSet,1,0
endon

On garage_open#Value=0 do
  //switch off light start blink
  GPIO,13,1
  timerSet,1,1
endon

On garage_open#Value=1 do
  //switch off blink and light on
  GPIO,13,0
  timerSet,1,0
endon

//create an actual warning signal, every time timer 1 expires:
On Rules#Timer=1 do 
   //repeat after 1 seconds
   timerSet,1,1
    //pulse the led shortly, non-blocking
   LongPulse_ms,13,0,400
endon
This works as follows:
Garage door closed: Light is off
Garage door is opening: Light blinks
Garage door is fully open: Light is on
Garage door is closing: Light blinks

An improvement could be to have 2 lights, orange for the current light, and green for a second light, that is turned on when the garage door is fully open, that would need these two events to be replaced by this code:
(Green light is on GPIO5, active low, orange light is on GPIO13, active low)

Code: Select all

On garage_open#Value=0 do
  //switch off light start blink
  GPIO,13,1
  GPIO,5,1
  timerSet,1,1
endon

On garage_open#Value=1 do
  //switch off blink and light on
  GPIO,13,1
  GPIO,5,0
  timerSet,1,0
endon
NB: Having 'Value' for the switches, instead of State, makes me wonder what version of ESPEasy you are using? I'd advise to take a current one form Github, like 20200410.

NB2: Having a switch on GPIO2 might get you in trouble, as that is used to put the ESP into one of its special modes during boot. Another GPIO should better be used like 3 or 5.

Edit: Updated to first turn on/off lights and then (re)set the timer.

Re: 2 Switch, 1 LED blink and light

Posted: 10 May 2020, 21:01
by druckgott
Hallo, I use version 120.

For the level you mean like in the picture.
The switches i also add pictures

I tested the pulse with the url command, bit it says unknown command

http://192.168.0.42/control?cmd=LongPulse_mS,13,1,400

The rules i also add but its not working, i will test it again tomorrow

Re: 2 Switch, 1 LED blink and light

Posted: 10 May 2020, 21:16
by Ath
Oefff, version 120 is over 2 years old, and not very up to date, so that's why you are missing the LongPulse_Ms command.

As I suggested earlier, please upgrade to a more current release, there have been many after R120, the latest is always available from here: https://github.com/letscontrolit/ESPEasy/releases and the zip-file includes an updated flash tool, as I'm not sure if your old version can install updates OTA (over the air).

Re: 2 Switch, 1 LED blink and light

Posted: 10 May 2020, 21:28
by druckgott
Ok thx thisbis what i found on the wiki 😁
I will updaten it tomorrow. And test it again.

Re: 2 Switch, 1 LED blink and light

Posted: 10 May 2020, 21:50
by druckgott
One more question is it also posible to send a puls with lower voltage or pwm so that the led only has 50 percent light?

Re: 2 Switch, 1 LED blink and light

Posted: 10 May 2020, 22:01
by grovkillen
Use the PWM command.

Re: 2 Switch, 1 LED blink and light

Posted: 11 May 2020, 17:33
by druckgott
Now it works thc

Can i combine pwm and longpulse?

I want to habe a differt lightsize between day and night and want to do this this the time.

Code: Select all

On garage_close#State=0 do
  //stop blinking
  timerSet,1,0
// Light off
  GPIO,13,0
endon

On garage_close#State=1 do
  //blink
  timerSet,1,1
endon

On garage_open#State=0 do
  //Light on
  GPIO,13,1
  timerSet,1,0
endon

On garage_open#State=1 do
  //switch off blink and light on
  GPIO,13,0
  timerSet,1,1
endon

//create an actual warning signal, every time timer 1 expires:
On Rules#Timer=1 do 
   //repeat after 1 seconds
   timerSet,1,1
    //pulse the led shortly, non-blocking
   LongPulse_ms,13,0,400
endon

Re: 2 Switch, 1 LED blink and light

Posted: 11 May 2020, 18:27
by grovkillen
I think you need to set PWM to zero before you can use the pulse commands. Or else it will not work. So if you have used the PWM command, set it to PWM level zero before using GPIO or pulse commands.

You can use fade for PWM fading.

Re: 2 Switch, 1 LED blink and light

Posted: 11 May 2020, 18:46
by druckgott
Ok so i can note have pulse with only 50 percent pwm signal? Pulse is only 100 percent power for the led if I understand it the right way?

Re: 2 Switch, 1 LED blink and light

Posted: 29 Apr 2021, 11:14
by TD-er
BriniGurhi wrote: 29 Apr 2021, 10:32 Is it also posible to send a puls with lower voltage so that the led only has 50 percent light?
You could add a small capacitor (and a small resistor to limit the charging current) and a resistor over the capacitor (to discharge the capacitor) to convert the PWM signal to an analog voltage.
It may require some experimentation to get the right value for the capacitor for your setup.

Re: 2 Switch, 1 LED blink and light

Posted: 29 Apr 2021, 11:49
by Ath
A LED is fast enough to react to the PWM command, afaics. It probably isn't linear in behavior, but you could play a little with duty-cycle and frequency to get the brightness as desired.