2 Switch, 1 LED blink and light

Moderators: grovkillen, TD-er, Stuntteam

Post Reply
Message
Author
druckgott
Normal user
Posts: 8
Joined: 08 May 2020, 20:47

2 Switch, 1 LED blink and light

#1 Post by druckgott » 10 May 2020, 10:08

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.

User avatar
Ath
Normal user
Posts: 69
Joined: 10 Jun 2018, 12:06
Location: NL

Re: 2 Switch, 1 LED blink and light

#2 Post by Ath » 10 May 2020, 13:30

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.

druckgott
Normal user
Posts: 8
Joined: 08 May 2020, 20:47

Re: 2 Switch, 1 LED blink and light

#3 Post by druckgott » 10 May 2020, 21:01

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
Attachments
Screenshot_20200510_205851_com.android.chrome.jpg
Screenshot_20200510_205851_com.android.chrome.jpg (256.43 KiB) Viewed 711 times
Screenshot_20200510_210108_com.android.chrome.jpg
Screenshot_20200510_210108_com.android.chrome.jpg (234.88 KiB) Viewed 711 times
Screenshot_20200510_210116_com.android.chrome.jpg
Screenshot_20200510_210116_com.android.chrome.jpg (238.85 KiB) Viewed 711 times
Last edited by druckgott on 10 May 2020, 21:17, edited 1 time in total.

User avatar
Ath
Normal user
Posts: 69
Joined: 10 Jun 2018, 12:06
Location: NL

Re: 2 Switch, 1 LED blink and light

#4 Post by Ath » 10 May 2020, 21:16

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).

druckgott
Normal user
Posts: 8
Joined: 08 May 2020, 20:47

Re: 2 Switch, 1 LED blink and light

#5 Post by druckgott » 10 May 2020, 21:28

Ok thx thisbis what i found on the wiki 😁
I will updaten it tomorrow. And test it again.

druckgott
Normal user
Posts: 8
Joined: 08 May 2020, 20:47

Re: 2 Switch, 1 LED blink and light

#6 Post by druckgott » 10 May 2020, 21:50

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?

User avatar
grovkillen
Core team member
Posts: 3584
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: 2 Switch, 1 LED blink and light

#7 Post by grovkillen » 10 May 2020, 22:01

Use the PWM command.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

druckgott
Normal user
Posts: 8
Joined: 08 May 2020, 20:47

Re: 2 Switch, 1 LED blink and light

#8 Post by druckgott » 11 May 2020, 17:33

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

User avatar
grovkillen
Core team member
Posts: 3584
Joined: 19 Jan 2017, 12:56
Location: Hudiksvall, Sweden
Contact:

Re: 2 Switch, 1 LED blink and light

#9 Post by grovkillen » 11 May 2020, 18:27

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.
ESP Easy Flasher [flash tool and wifi setup at flash time]
ESP Easy Webdumper [easy screendumping of your units]
ESP Easy Netscan [find units]
Official shop: https://firstbyte.shop/
Sponsor ESP Easy, we need you :idea: :idea: :idea:

druckgott
Normal user
Posts: 8
Joined: 08 May 2020, 20:47

Re: 2 Switch, 1 LED blink and light

#10 Post by druckgott » 11 May 2020, 18:46

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?

Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 40 guests