Hi everyone,
I’m here asking for a tiny fix that has to do with PWM and Json Packages. Basically I’m controlling a neon lamp transformer to change the tube’s brightness. My code runs almost perfectly and it would be perfect if I were able to do a soft dim. So far the dimmer works but it is too fast to perceive the steps it takes to reach the specified brightness. Its a very simple code, I don’t understand why my Imp’s stepping is imperceptible or how to dial in the speed for my FOR loop
Here’s my device code:
neonWhite <- hardware.pin1;
neonWhite.configure(PWM_OUT, 0.0167, 0.0);
neonBlue <- hardware.pin2;
neonBlue.configure(PWM_OUT, 0.0167, 0.0);
// Record the state and delta of the LED’s cycle
neonState <- 0.6;
neonChange <- 0.006;
newState <- 0.0;
function dim1(white) {
newState = neonState - (white.tofloat() * 0.006);
server.log("White lamp state is " + white + “%”);
action();
}
function dim2(blue) {
newState = neonState - ((blue.tofloat() * 0.006));
server.log("Blue lamp state is " + blue + “%”);
}
function action() {
for(local x = neonState; x >= newState; x -= neonChange){
neonWhite.write(x);
}
for(local y = neonState; y <= newState; y +=neonChange){
neonWhite.write(y);
//server.log(x);
}
}
agent.on(“white”, dim1);
agent.on(“blue”, dim2);
Any advice will be greatly appreciated