analogWrite(pin, dutycycle): Enables software PWM on the specified pin. duty cycleis in the range from 0 to PWMRANGE, i.e. 1023 by default.
analogWrite(pin, 0): Disables PWM on specified pin.
analogWriteRange(new_range): This function is used to change PWM range (duty cycle).
analogWriteFreq(new_frequency): PWM frequency is 1kHz by default. Call this function to change it with new frequency.PWM frequency is in the range 1 – 1000Khz.
not necessary an LED connect on gpio14 (D5 and GND) : working without pinMode();
connect to cayenne and wifi account + this code :
CAYENNE_IN(10)
{
int currentValue = getValue.asInt();
int pwmLed = map(currentValue, 0, 100, 0, 1023);
Serial.print(“\nGet slide cmd :”); Serial.println(currentValue);
Serial.print(“Set pwm led :”); Serial.println(pwmLed);
analogWrite(14, pwmLed);
}
result on serial and (LED light with different state) :
[11481] Connecting to mqtt.mydevices.com:1883
[12083] Connected
Get slide cmd :35
Set pwm led :358
Get slide cmd :2
Set pwm led :20
Get slide cmd :97
Set pwm led :992
I try everything, but the device still does not want to work
I was try to change the0-255 to 0-1203, try to SuperNinja code too,
I measure it and if i change the slider value, the input doesnt want to change. i wiil need 0-3.3V to control the fan, but it always 0.
Pls help.
@ory.gabriel so the problem you are facing is to control a fan using a slider. we will solve this one step at a time.
are you able to read slider value on the serial monitor when you change the position of the slider on the dashboard.
If i change the slider position, the serial monitor read it, but the output pin dont change, always same V, but if output is 0V then the fan is stopped, if the output volt is 3.3V the fan is run full speed
Now for this code tha fan work this method: i set 10 to slider step value, if i set 0 the fan stop, but if a set between 10-100 the fan run at full speed