Button to toggle RGB leds

Moderators: grovkillen, Stuntteam, TD-er

Post Reply
Message
Author
Tecumseh
Normal user
Posts: 37
Joined: 30 Sep 2016, 09:42

Button to toggle RGB leds

#1 Post by Tecumseh » 06 Nov 2018, 13:02

I am trying to create a selection toggle switch for my wife to operate a series of RGB leds. For this I want to have a button and on press cycle through a series of colors. What I did was create a variable with the Generic Dummy device and I can increase that value with a buttonpress and above a certain value (9 in my case) reset it to 0. What I don't have is a swift response on the rgb led, I currently change that based on the variable value but that change seems to take a long time until discovered. What can I change to have a prompt result after button press?

Code: Select all

on Touch#Button=1 do
  if [Var#Color]>9 do
    TaskValueSet 3,1,0
  else
    TaskValueSet 3,1,[Var#Color]+1
  endif
endon

on Var#Color=0 do
  neopixel,1,0,0,0 // Off
endon

on Var#Color=1 do
  neopixel,1,255,0,0 // Red
endon

on Var#Color=2 do
  neopixel,1,0,255,0 // Lime
endon

on Var#Color=3 do
  neopixel,1,0,0,0255 // Blue
endon

on Var#Color=4 do
  neopixel,1,255,255,0 // Yellow
endon

on Var#Color=5 do
  neopixel,1,0,255,255 // Cyan
endon

on Var#Color=6 do
  neopixel,1,255,0,255 // Magenta
endon

on Var#Color=7 do
  neopixel,1,128,0,0 // Maroon
endon

on Var#Color=8 do
  neopixel,1,128,128,0 // Olive
endon

on Var#Color=9 do
  neopixel,1,0,128,0 // Green
endon

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

Re: Button to toggle RGB leds

#2 Post by grovkillen » 06 Nov 2018, 15:57

Use task run command right after setting the task value for it to trigger the event.
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:

Tecumseh
Normal user
Posts: 37
Joined: 30 Sep 2016, 09:42

Re: Button to toggle RGB leds

#3 Post by Tecumseh » 07 Nov 2018, 00:13

Thanks, that worked brilliant. Here's the complete code used (device 3 is the dummy device)

Code: Select all

on Touch#Button=1 do
  if [Var#Color]>8 do
    TaskValueSet 3,1,0
    TaskRun,3
  else
    TaskValueSet 3,1,[Var#Color]+1
    TaskRun,3
  endif
endon

on Var#Color=0 do
  neopixel,1,0,0,0 // Off
endon

on Var#Color=1 do
  neopixel,1,255,0,0 // Red
endon

on Var#Color=2 do
  neopixel,1,0,255,0 // Lime
endon

on Var#Color=3 do
  neopixel,1,0,0,0255 // Blue
endon

on Var#Color=4 do
  neopixel,1,255,255,0 // Yellow
endon

on Var#Color=5 do
  neopixel,1,0,255,255 // Cyan
endon

on Var#Color=6 do
  neopixel,1,255,0,255 // Magenta
endon

on Var#Color=7 do
  neopixel,1,128,0,0 // Maroon
endon

on Var#Color=8 do
  neopixel,1,128,128,0 // Olive
endon

on Var#Color=9 do
  neopixel,1,0,128,0 // Green
endon

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

Re: Button to toggle RGB leds

#4 Post by grovkillen » 07 Nov 2018, 06:03

Great news :)
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:

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Button to toggle RGB leds

#5 Post by dynamicdave » 13 Nov 2018, 08:24

Which version of ESP Easy are you using?

I've been trying to make use of your rules with the November,2018 releases of mega-espeasy.
It would be interesting to know which version/release you have used.

Cheers from David.

Tecumseh
Normal user
Posts: 37
Joined: 30 Sep 2016, 09:42

Re: Button to toggle RGB leds

#6 Post by Tecumseh » 13 Nov 2018, 10:14

This unit runs on version mega-20180914, I'll update it tonight and see if that makes a difference

Tecumseh
Normal user
Posts: 37
Joined: 30 Sep 2016, 09:42

Re: Button to toggle RGB leds

#7 Post by Tecumseh » 13 Nov 2018, 19:13

Some bad news, I have just updated this unit to the latest nightly build (ESP_Easy_mega-20181112_normal_ESP8266_4096.bin) and now the ruleset is not working anymore.

Looking at this bit of code from the rules section:

Code: Select all

on Touch#Button=1 do
  if [Var#Color]>8 do
    TaskValueSet 3,1,0
    TaskRun,3
  else
    TaskValueSet 3,1,[Var#Color]+1
    TaskRun,3
  endif
endon
It looks like TaskValueSet 3,1,[Var#Color]+1 is being read as TaskValueSet 3,1,1, after changing this line to TaskValueSet 3,1,[Var#Color]+2 I am getting the next color in the sequence (variable 1 from device 3 is set to 2).

*edit*

After loading firmware ESP_Easy_mega-20181021_normal_ESP8266_4096.bin I have this functionality working again. Also tried version ESP_Easy_mega-20181107_normal_ESP8266_4096.bin but that one didn't work. I'll try to find the latest version when this still worked.

*edit 2*

After some trial and error I can report that ESP_Easy_mega-20181031_normal_ESP8266_4096.bin is the latest version where this feature works.

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Button to toggle RGB leds

#8 Post by dynamicdave » 13 Nov 2018, 19:52

Well that is eaxctly the same as the problem I'm seeing.
None of the November releases work with the incrementing a named-variable in the rules.
I agree with you, that the last version that works is 2018-10-31

Thanks for taking the time to check this out.

Cheers from David.

Domosapiens
Normal user
Posts: 307
Joined: 06 Nov 2016, 13:45

Re: Button to toggle RGB leds

#9 Post by Domosapiens » 13 Nov 2018, 20:20

Using mega-20181101

this part of my rules works !

Code: Select all

TaskvalueSet,3,2,([MUC19NAN#MUC19_NAN]+[rot#counter]/10)
Is using ( ....) these brackets the trick?
30+ ESP units for production and test. Ranging from control of heating equipment, flow sensing, floor temp sensing, energy calculation, floor thermostat, water usage, to an interactive "fun box" for my grandson. Mainly Wemos D1.

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Button to toggle RGB leds

#10 Post by dynamicdave » 13 Nov 2018, 20:48

Thanks - I'll give that a try tomorrow (as one of my students has borrowed the node with the NeoPixels this evening).

Cheers from David.

Tecumseh
Normal user
Posts: 37
Joined: 30 Sep 2016, 09:42

Re: Button to toggle RGB leds

#11 Post by Tecumseh » 13 Nov 2018, 21:00

Using the latest nightly build and the following code still no success:

Code: Select all

on Touch#Button=1 do
  if [Var#Color]>8 do
    TaskValueSet 3,1,0
    TaskRun,3
  else
    TaskValueSet,3,1,([Var#Color]+1)
    TaskRun,3
  endif
endon

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Button to toggle RGB leds

#12 Post by dynamicdave » 13 Nov 2018, 21:04

Oh that's annoying - I thought the hint about (....) made sense and would solve the problem.

Thanks for trying it out.

PS:
I've just noticed that on line-3 you have TaskValueSet 3,1,0
and on line-6 you have TaskValueSet,3,1,([Var#Color]+1)

i.e. one with a space and one with a comma.
I'm clutching at straws and trying all sorts of combinations to get this rule working.

on Touch#Button=1 do
if [Var#Color]>8 do
TaskValueSet 3,1,0
TaskRun,3
else
TaskValueSet,3,1,([Var#Color]+1)
TaskRun,3
endif
endon

Tecumseh
Normal user
Posts: 37
Joined: 30 Sep 2016, 09:42

Re: Button to toggle RGB leds

#13 Post by Tecumseh » 13 Nov 2018, 21:34

dynamicdave wrote: 13 Nov 2018, 21:04PS:
I've just noticed that on line-3 you have TaskValueSet 3,1,0
and on line-6 you have TaskValueSet,3,1,([Var#Color]+1)

i.e. one with a space and one with a comma.
I'm clutching at straws and trying all sorts of combinations to get this rule working.
Yes on another forumtopic I saw a comment (from you I think) that it was better to use the comma then the space as currently the spaces are interpreted as comma's but that could change in the future. Therefor I made a couple of changes in the code. With the october 31th version that gave me no problem but I figured reverting to the original code for testing version compatability would be best. Must have missed one instance still.

User avatar
dynamicdave
Normal user
Posts: 257
Joined: 30 Jan 2017, 20:25
Location: Hampshire, UK

Re: Button to toggle RGB leds

#14 Post by dynamicdave » 14 Nov 2018, 11:10

Success.... I've been given the answer/reason why the named-variable didn't work in 'rules'.
- - - - - - - -
Hi,
I got it now! See #1986.
The problem with your rule is that [Var#n] is a reserved command that retrieves the system variable %Vn%.

Wiki should be updated with this new commands and system variables.
- - - - - - - -

Post Reply

Who is online

Users browsing this forum: Google [Bot] and 20 guests