Page 1 of 1

Button to toggle RGB leds

Posted: 06 Nov 2018, 13:02
by Tecumseh
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

Re: Button to toggle RGB leds

Posted: 06 Nov 2018, 15:57
by grovkillen
Use task run command right after setting the task value for it to trigger the event.

Re: Button to toggle RGB leds

Posted: 07 Nov 2018, 00:13
by Tecumseh
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

Re: Button to toggle RGB leds

Posted: 07 Nov 2018, 06:03
by grovkillen
Great news :)

Re: Button to toggle RGB leds

Posted: 13 Nov 2018, 08:24
by dynamicdave
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.

Re: Button to toggle RGB leds

Posted: 13 Nov 2018, 10:14
by Tecumseh
This unit runs on version mega-20180914, I'll update it tonight and see if that makes a difference

Re: Button to toggle RGB leds

Posted: 13 Nov 2018, 19:13
by Tecumseh
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.

Re: Button to toggle RGB leds

Posted: 13 Nov 2018, 19:52
by dynamicdave
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.

Re: Button to toggle RGB leds

Posted: 13 Nov 2018, 20:20
by Domosapiens
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?

Re: Button to toggle RGB leds

Posted: 13 Nov 2018, 20:48
by dynamicdave
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.

Re: Button to toggle RGB leds

Posted: 13 Nov 2018, 21:00
by Tecumseh
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

Re: Button to toggle RGB leds

Posted: 13 Nov 2018, 21:04
by dynamicdave
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

Re: Button to toggle RGB leds

Posted: 13 Nov 2018, 21:34
by Tecumseh
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.

Re: Button to toggle RGB leds

Posted: 14 Nov 2018, 11:10
by dynamicdave
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.
- - - - - - - -