Out of memory issue

I found out an issue when I was simply trying a fading of an LED sketch. Maybe Hugo/anyone else can clarify a workaround. So Iwas getting some error messages as follows:

Power state: online=>offline imp crashed, reason: out of memory

I simply commented out the log and everything is fine. is there a workaround for this?

Would have to see your code to comment; if it’s closely related to the ones you posted before, then I’d be very surprised if they were running out of memory but maybe there’s a VM bug or you’re building up orphaned objects somewhere…

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()], []);`

thanks again.

You still haven’t explained what you’re actually trying to do. If you don’t really care about ticktocks or inputs, and just want to fade an LED up and down, that’s much simpler than what you’ve got:
value <- 0; change <- 1; imp.configure("LED fade",[],[]); hardware.pin9.configure(PWM_OUT, 0.02, 0.0); function poll() { value += change; if (value == 255) { change = -1; } else if (value == 0) { change = +1; } hardware.pin9.write(value/256.0); imp.wakeup(0.01, poll); } poll();

Peter

Hey peter, thanks for the suggestion.

two things: just to note:

the bits where you at a +1 are
change=change+1 instead.

and this is exactly what I was looking for.I was a bit confused just thumbing through the documentation and understanding what is required for specific events in the Imp IDE.

sorry for the lack of clarification also; I am simply networking a few imps that will be communicating to each other, and triggering events such as fading led’s, etc.