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);
Espruino is a JavaScript interpreter for low-power Microcontrollers. This site is both a support community for Espruino and a place to share what you are working on.
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?