function to control an rgb led #7584
Replies: 1 comment
-
Posted at 2017-04-03 by @gfwilliams Hi! As you saw, your problem is really that you're not writing async code (plus You probably want something like this:
This starts off fading through colors, but when you press a button it'll add a new color to the end of colors to fade to Posted at 2017-04-03 by azer wow, i'll test this asap :) Posted at 2017-04-03 by azer it's working but is it possible to fade from 0 (black) to randoms colours automatically ?
I have a big logical problem for that. I presume that it is not so difficult but I can't really understand how it works ! Posted at 2017-04-04 by @gfwilliams Sure - if you're doing that, it sounds like you don't need the
You could also look at using this function: http://www.espruino.com/Reference#l_E_HSBtoRGB Probably what you want is a random hue, but keeping the same brightness and saturation, and that function will help you. You will however need to extract the RGB values from the 24 bit number, which is a bit cryptic:
Posted at 2017-04-04 by azer There is something I missed. When the board starts, the led is off. Good. When I press the button, the led start directly and is not fading. The color jump from one to another one
Posted at 2017-04-05 by @gfwilliams That looks good - but what code have you got for the button press? Posted at 2017-04-05 by azer Sorry for the late answer. I can't access to my personal documents from work.
Posted at 2017-04-06 by @gfwilliams So you're actually using this on an ESP8266? Why did you post on the official boards forum? Posted at 2017-04-06 by azer Hello, I use nodemcu. Ordinary I post in other boards topic. For this I have done a mistake. Sorry for that. Posted at 2017-04-06 by @gfwilliams Ok, no problem. Obviously it takes a while for me to write that code for you, and I can't afford to keep doing that for folks that aren't using official boards :) I'll move this to the 'General' other boards section. Some obvious stuff I notice:
Posted at 2017-04-07 by azer hello, I've just make corrections suggested. It's working. But the colors jumps from color to another one. How can I make a fading animation between colors ?
Posted at 2017-04-08 by Robin Have you attempted this tutorial yet? It has a fading effect between colors, similar to that which you might be seeking. @gfwilliams has spent a considerable amount of his valuable time coding a framework for you to hang your work on. It would be prudent to blend the above tutorial example into your work to get the desired effect you are after. It is difficult for anyone to write a solution to an idea you have firmly cemented in your mind. A bit of study should provide the insight to a solution to that which you envision. I'm sure you will be proud of your own effort once you achieve success.
Posted at 2017-04-08 by azer Hi. I've already tried lot of tutos found over the net. But there is a lot of them for official espruino boards so it doesn't works on mine. I'm not a big pro developper but i have lots of boards programed by myself. But i never had to use rgb leds with this board. I've just tried to control my led using an Arduino Uno. It works very well. So while looking for fading on esp, i found that esp can't use hard pwm. That's why all my test codes doesn't works as expected. I have found a soft pwm fonction to do the same work. I'll try it. https://www.espruino.com/Software+PWM Thank you for all helps @gfwilliams |
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
-
Posted at 2017-04-02 by azer
Hi, forgive me for my bad english.
I'm trying to control a simple RGB led. My actual code is working, but I'd make it more ... fluid:
I call this funtion with the pin number of the led to control. But I'd like an async function that can run a "sequence" of colours while checking in the same time the state of a push button (to turn on/off).
I'm really not a developper, but I know that someone could help me to finish my little led lamp project for my daughter :)
Beta Was this translation helpful? Give feedback.
All reactions