You are reading a single comment by @azer and its replies. Click here to read the full conversation.
  • 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();
    
About

Avatar for azer @azer started