Hey Hugo, heres the code below (new and working):
`// Control a LED intensity throught PWM Control
// Show program name in logs window
server.log(“Start PWM LED Intensity”);
//local nvalue;
// Set pin to PWM, with a 20 ms period and duty cycle to 1 (default)
hardware.pin7.configure(PWM_OUT, 0.02, 1.0);
hardware.pin8.configure(PWM_OUT, 0.02, 1.0);
hardware.pin9.configure(PWM_OUT, 0.02, 1.0);
local nextLoop = 0.0;
local lastLoop = 0.0;
// Create inputPort and correspondent function light the LED
class LEDintensity extends InputPort
{
// Set name and type of input port
name = “InputAnalog”;
type = “number”;
// Create function to light the LED
function set(value)
{
if (nextLoop==0.0){
// local new_val = scale(value, 0, 1.0, 0, 256.0);
for(local value=0.0; value<=1.0; value+=0.02){
// Write PWM value accordingly to the input value. Divide by 65535 to get a value between 0 and 1
hardware.pin7.write(value/1.0);
///server.log(format("%.2f", value));
imp.sleep(0.04);
// return 0;
}
for(local value=1.0; value>=0.0; value-=0.02){
// Write PWM value accordingly to the input value. Divide by 65535 to get a value between 0 and 1
hardware.pin7.write(value/1.0);
//server.log(format("%.2f", value));
imp.sleep(0.04);
//return 0;
}
nextLoop=1.0;
}
if (nextLoop==1.0){
// local new_val = scale(value, 0, 1.0, 0, 256.0);
for(local value=0.0; value<=1.0; value+=0.02){
// Write PWM value accordingly to the input value. Divide by 65535 to get a value between 0 and 1
hardware.pin8.write(value/1.0);
///server.log(format("%.2f", value));
imp.sleep(0.04);
}
for(local value=1.0; value>=0.0; value-=0.02){
// Write PWM value accordingly to the input value. Divide by 65535 to get a value between 0 and 1
hardware.pin8.write(value/1.0);
//server.log(format("%.2f", value));
imp.sleep(0.04);
//return 0;
}
lastLoop = 1.0;
}
if(lastLoop==1.0){
for(local value=0.0; value<=1.0; value+=0.02){
// Write PWM value accordingly to the input value. Divide by 65535 to get a value between 0 and 1
hardware.pin9.write(value/1.0);
imp.sleep(0.04);
}
for(local value=1.0; value>=0.0; value-=0.02){
// Write PWM value accordingly to the input value. Divide by 65535 to get a value between 0 and 1
hardware.pin9.write(value/1.0);
//server.log(format("%.2f", value));
imp.sleep(0.04);
}
nextLoop=0.0;
}
}
}
/////////////////////
// Configure imp in the server
imp.configure(“PWM LED Intensity”, [LEDintensity()], []);`