-
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 ?
// variables to set var wifiSSID = "xxxx"; var wifiPass = "xxxx"; // do not touch after this line var LED1 = D5; var LED2 = D14; var LED3 = D12; var button = D4; var colFrom = [0,0,0]; var colTo = [0,0,0]; var colFade = 0; var powerState = "off"; pinMode(button, 'input_pulldown'); function setLeds() { colFade += 0.5; if (colFade>=1) { colFade = 0; colFrom = colTo; var c = E.HSBtoRGB(Math.random(),1,1); colTo = [ (c&0xFF)/256, ((c>>8)&0xFF)/256, ((c>>16)&0xFF)/256 ]; } analogWrite(LED1,colFrom[0]*(1-colFade) + colTo[0]*colFade, {soft:true}); analogWrite(LED2,colFrom[1]*(1-colFade) + colTo[1]*colFade, {soft:true}); analogWrite(LED3,colFrom[2]*(1-colFade) + colTo[2]*colFade, {soft:true}); } function power(state) { if (state === "on") { powerState = "on"; setInterval(setLeds, 500); } if (state === "off") { powerState = "off"; clearInterval(); analogWrite(LED1, false); analogWrite(LED2, false); analogWrite(LED3, false); } } function startServer() { setWatch(function(){ if (powerState === "off") { power("on"); powerState = "on"; } else { if (powerState === "on") { power("off"); powerState = "off"; } } }, button, {repeat:true, edge:"rising", debounce:50}); } function onInit() { var wifi = require('Wifi'); wifi.stopAP(); wifi.connect(wifiSSID, {password:wifiPass}, function(err, data){ if (err) { print('Error while connecting to access point' + wifiSSID); return; } print("connected? err=", err, "info=", wifi.getIP()); startServer(); }); } power('off');
-
-
Sorry for the late answer. I can't access to my personal documents from work.
Here it i the full code:// variables to set var wifiSSID = "xxxx"; var wifiPass = "xxxx"; // do not touch after this line var LED1 = D5; var LED2 = D14; var LED3 = D12; var button = D4; var colFrom = [0,0,0]; var colTo = [0,0,0]; var colFade = 0; pinMode(button, 'input_pulldown'); function setLeds() { colFade += 0.05; if (colFade>=1) { colFade = 0; colFrom = colTo; var c = E.HSBtoRGB(Math.random(),1,1); colTo = [ (c&0xFF)/256, ((c>>8)&0xFF)/256, ((c>>16)&0xFF)/256 ]; } analogWrite(LED1,colFrom[0]*(1-colFade) + colTo[0]*colFade, {soft:true}); analogWrite(LED2,colFrom[1]*(1-colFade) + colTo[1]*colFade, {soft:true}); analogWrite(LED3,colFrom[2]*(1-colFade) + colTo[2]*colFade, {soft:true}); } function power(state) { if (state === "on") { powerState = "on"; setInterval(setLeds, 500); } if (state === "off") { powerState = "off"; analogWrite(LED1, false); analogWrite(LED2, false); analogWrite(LED3, false); } } function startServer() { // start future http server var powerState = "off"; power("off"); setWatch(function(){ if (powerState === "off") { power("on"); powerState = "on"; } else { if (powerState === "on") { power("off"); powerState = "off"; } } }, button, {repeat:true, edge:"rising", debounce:50}); } function onInit() { var wifi = require('Wifi'); wifi.stopAP(); wifi.connect(wifiSSID, {password:wifiPass}, function(err, data){ if (err) { print('Error while connecting to access point' + wifiSSID); return; } print("connected? err=", err, "info=", wifi.getIP()); startServer(); }); } E.on('init', onInit()); save();
-
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
function setLeds() { colFade += 0.05; if (colFade>=1) { colFade = 0; colFrom = colTo; var c = E.HSBtoRGB(Math.random(),1,1); colTo = [ (c&0xFF)/256, ((c>>8)&0xFF)/256, ((c>>16)&0xFF)/256 ]; } analogWrite(LED1,colFrom[0]*(1-colFade) + colTo[0]*colFade, {soft:true}); analogWrite(LED2,colFrom[1]*(1-colFade) + colTo[1]*colFade, {soft:true}); analogWrite(LED3,colFrom[2]*(1-colFade) + colTo[2]*colFade, {soft:true}); }
-
it's working but is it possible to fade from 0 (black) to randoms colours automatically ?
Exemple:- Push button --> start led sequence from 0, 0, 0 (R, G, B)
- calculate new random values for each led
- fade from 0, 0, 0 to new values a, b, c
- When fade done, calculate new random values
- fade from a, b, c to new values d, e, f
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 !
- Push button --> start led sequence from 0, 0, 0 (R, G, B)
-
-
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:
function fade(led) { for (i=0; i<=255; i++) { digitalWrite(led, i); } }
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 :)
-
-
Hi, forgive me for my bad english.
I'm using a nodemcu devkit 0.9 with espruino v1.89. When I add these lines, my board seems to crash. I can't get the prompt and i have to disconnect en reconnect the board to usb, then make a reset. If i remove these lines, everything is fine.
'<script>'+ 'function postForm(e) {'+ 'e.preventDefault();'+ 'var mode = document.getElementById("mode").value;'+ 'var hostname = document.getElementById("hostname").value;'+ 'var ssid = document.getElementById("wifiSSID").value;'+ 'var pass = document.getElementById("wifiPass").value;'+ 'var data = { "mode": mode, "hostname": hostname, "ssid": ssid, "pass": pass };'+ 'var xmlhttp = new XMLHttpRequest();'+ 'xmlhttp.open("POST", "/save");'+ 'xmlhttp.setRequestHeader("Content-Type", "application/json;charset=UTF-8");'+ 'xmlhttp.send(JSON.stringify(data);'+ '}'+
This is the memory without these lines:
={ "free": 1332, "usage": 368, "total": 1700, "history": 383 }So it's not a problem with memory limit. It seems to be a problem with xmlhttp.open, xmlhttp.setRequestHeader and xmlhttp.send. The problem appears just when I add the 3 lines. Any idea ??
-
-
Hi, forgive me for my bad english.
1st question: is it possible to import in html page an external lib like jquery ? My esp is not connected to internet so I can't load it from an url.
2nd question: I have found this doc from official espruino documentation (https://www.espruino.com/Internet)
Can I use this code in html client side or it's just for the server side ?
Thanks in advance for your helps.
-
-
Yes it is exactly that. But I don't have any sdcard connected to the esp. The link provided explain how to save data to an sdcard. I just want to save 4 parameters on memory:
1 - default ssid in ad-hoc mod
2 - default password
3 - user ssid
4 - user passwordIf I use the code in link provided, is there a way to save the file in json format in memory of the esp ?
-
Hi, please forgive me for my bad english.
I have several esp8266 running with espruino. All of them are running very well. But I'd like to permit to change the wifi settings over HTTP. I have one page (/) wher eI can put some fields like "ssid name", "ssid password". But I don't know how I can save these values in my program. I think that I have to change my program to get these value in memory, but I don't know if there is the good solution.
Is someone have an idea ?
Thanks.
-
-
OK for the wifi parameter. I will remove the wifi.save function. The sonoff module use an input directly from the main power (90V-250V) and has his own convertor: https://www.itead.cc/sonoff-wifi-wireless-switch.html
-
Hi, forgive me for my bad english. I'm using a sonoff module that have a relay and a led. I have falsh firmware with espruino v1.87 and I have wrote a code to control the relay and the led from a we page.
If I use the board connected on USB, it works well. But when I add the save() function, I can't control anymore the relay and the led. If I plugg off the usb and connect the board to 220V (france), the board is not responding on wifi. So I think that the board doesn't store my code:
var relay = D12; var led = D13; function toggleDevice(toggle){ digitalWrite(relay, toggle); digitalWrite(led, toggle); } function startServer() { var http = require('http'); var httpServer = http.createServer(function(req, res) { var params = url.parse(req.url, true); if (params.query !== null && params.query.device !== "") { var status = params.query.device; toggleDevice(status); } res.end("<h1>Hello world</h1>"); }); httpServer.listen(80); print('HTTP server is running'); } function onInit() { var wifiSSID = "xxxxxx"; var wifiPass = "xxxxxxxx"; var wifi = require('Wifi'); wifi.connect(wifiSSID, {password:wifiPass}, function(err, data){ if (err) { print('Error while connecting to access point' + wifiSSID); return; } print("connected? err=", err, "info=", wifi.getIP()); startServer(); }); wifi.stopAP(); wifi.save(); } E.on('init', onInit()); //save();
Any idea please ?
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 @Gordon