You are reading a single comment by @user52526 and its replies. Click here to read the full conversation.
  • In theory, the toggle function in the code below would create a PWM with a 1kHtz frequency with a 50% duty cycle, but I know there are some limitations to the hardware, has anybody tried something like this before?

    function myFunction() {
      var pin,High,Low;
      if (arguments[0]) pin = arguments[0];
      else pin = LED1;
      
      if (arguments[1]) High = arguments[1]; 
      else High = 1000;
      
      if (arguments[2]) Low = arguments[2];
      else Low = 1000;
      
      function toggle () {
        if (obj.on) {
          obj.toggle = setTimeout(toggle,Low);
          obj.on = false;
          digitalWrite(pin,0);
        } else {
          obj.toggle = setTimeout(toggle,High);
          obj.on = true;
          digitalWrite(pin,1);
        }
      }
      
      var obj = {
        on: true,
        toggle: setTimeout(toggle,High)
      };
    }
    
    myFunction(C11,1,1);
    
About

Avatar for user52526 @user52526 started