/*JSON{ "type":"function", "name" : "analogWrite", "description" : "Set the analog Value of a pin. It will be output using PWM", "generate" : "jswrap_io_analogWrite", "params" : [ [ "pin", "pin", "The pin to use"], [ "value", "float", "A value between 0 and 1"], [ "options", "JsVar", ["An object containing options.", "Currently only freq (pulse frequency in Hz) is available: ```analogWrite(A0,0.5,{ freq : 10 });``` ", "Note that specifying a frequency will force PWM output, even if the pin has a DAC"] ] ] }*/ void jswrap_io_analogWrite(Pin pin, JsVarFloat value, JsVar *options) { JsVarFloat freq = 0; if (jsvIsObject(options)) { freq = jsvGetFloatAndUnLock(jsvObjectGetChild(options, "freq", 0)); } jshPinAnalogOutput(pin, value, freq); }
/*JSON{ "type":"function", "name" : "analogWrite", "description" : "Set the analog Value of a pin. It will be output using PWM", "generate" : "jswrap_io_analogWrite", "params" : [ [ "pin", "pin", "The pin to use"], [ "value", "float", "A value between 0 and 1"], [ "options", "JsVar", ["An object containing options.", "Currently only freq (pulse frequency in Hz) is available: ```analogWrite(LED1,0.5,{ freq : 10 });``` ", "Note that specifying a frequency will force PWM output, even if the pin has a DAC"] ] ] }*/ void jswrap_io_analogWrite(Pin pin, JsVarFloat value, JsVar *options) { JsVarFloat freq = 0; if (jsvIsObject(options)) { freq = jsvGetFloatAndUnLock(jsvSkipNameAndUnLock(jsvFindChildFromString(options, "freq", false))); } jshPinAnalogOutput(pin, value, freq); }
/*JSON{ "type" : "function", "name" : "analogWrite", "generate" : "jswrap_io_analogWrite", "params" : [ ["pin","pin",["The pin to use","You can find out which pins to use by looking at [your board's reference page](#boards) and searching for pins with the `PWM` or `DAC` markers."]], ["value","float","A value between 0 and 1"], ["options","JsVar",["An object containing options for analog output - see below"]] ] } Set the analog Value of a pin. It will be output using PWM. Objects can contain: * `freq` - pulse frequency in Hz, eg. ```analogWrite(A0,0.5,{ freq : 10 });``` - specifying a frequency will force PWM output, even if the pin has a DAC * `soft` - boolean, If true software PWM is used if available. * `forceSoft` - boolean, If true software PWM is used even **Note:** if you didn't call `pinMode` beforehand then this function will also reset pin's state to `"output"` */ void jswrap_io_analogWrite(Pin pin, JsVarFloat value, JsVar *options) { JsVarFloat freq = 0; JshAnalogOutputFlags flags = JSAOF_NONE; if (jsvIsObject(options)) { freq = jsvGetFloatAndUnLock(jsvObjectGetChild(options, "freq", 0)); if (jsvGetBoolAndUnLock(jsvObjectGetChild(options, "forceSoft", 0))) flags |= JSAOF_FORCE_SOFTWARE; else if (jsvGetBoolAndUnLock(jsvObjectGetChild(options, "soft", 0))) flags |= JSAOF_ALLOW_SOFTWARE; } jshPinAnalogOutput(pin, value, freq, flags); }